/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* The X509CertInfo class represents X.509 certificate information.
*
* <P>X.509 certificates have several base data elements, including:<UL>
*
* <LI>The <em>Subject Name</em>, an X.500 Distinguished Name for
* the entity (subject) for which the certificate was issued.
*
* <LI>The <em>Subject Public Key</em>, the public key of the subject.
* This is one of the most important parts of the certificate.
*
* <LI>The <em>Validity Period</em>, a time period (e.g. six months)
* within which the certificate is valid (unless revoked).
*
* <LI>The <em>Issuer Name</em>, an X.500 Distinguished Name for the
* Certificate Authority (CA) which issued the certificate.
*
* <LI>A <em>Serial Number</em> assigned by the CA, for use in
* certificate revocation and other applications.
*
* @author Amit Kapoor
* @author Hemma Prafullchandra
* @see CertAttrSet
* @see X509CertImpl
*/
/**
* Identifier for this attribute, to be used with the
* get, set, delete methods of Certificate, x509 type.
*/
// Certificate attribute names
// X509.v1 data
// X509.v2 & v3 extensions
// X509.v3 extensions
// Attribute numbers for internal manipulation
// DER encoded CertificateInfo data
// The certificate attribute name to integer mapping stored here
static {
}
/**
* Construct an uninitialized X509CertInfo on which <a href="#decode">
* decode</a> must later be called (or which may be deserialized).
*/
public X509CertInfo() { }
/**
* Unmarshals a certificate from its encoded form, parsing the
* encoded bytes. This form of constructor is used by agents which
* need to examine and use certificate contents. That is, this is
* one of the more commonly used constructors. Note that the buffer
* must include only a certificate, and no "garbage" may be left at
* the end. If you need to ignore data at the end of a certificate,
* use another constructor.
*
* @param cert the encoded bytes, with no trailing data.
* @exception CertificateParsingException on parsing errors.
*/
try {
} catch (IOException e) {
new CertificateParsingException(e.toString());
throw parseException;
}
}
/**
* Unmarshal a certificate from its encoded form, parsing a DER value.
* This form of constructor is used by agents which need to examine
* and use certificate contents.
*
* @param derVal the der value containing the encoded cert.
* @exception CertificateParsingException on parsing errors.
*/
try {
} catch (IOException e) {
new CertificateParsingException(e.toString());
throw parseException;
}
}
/**
* Appends the certificate to an output stream.
*
* @param out an output stream to which the certificate is appended.
* @exception CertificateException on encoding errors.
* @exception IOException on other errors.
*/
throws CertificateException, IOException {
if (rawCertInfo == null) {
}
}
/**
* Return an enumeration of names of attributes existing within this
* attribute.
*/
}
/**
* Return the name of this attribute.
*/
return(NAME);
}
/**
* Returns the encoded certificate info.
*
* @exception CertificateEncodingException on encoding information errors.
*/
try {
if (rawCertInfo == null) {
}
return rawCertInfo.clone();
} catch (IOException e) {
throw new CertificateEncodingException(e.toString());
} catch (CertificateException e) {
throw new CertificateEncodingException(e.toString());
}
}
/**
* Compares two X509CertInfo objects. This is false if the
* certificates are not both X.509 certs, otherwise it
* compares them as binary data.
*
* @param other the object being compared with this one
* @return true iff the certificates are equivalent
*/
if (other instanceof X509CertInfo) {
} else {
return false;
}
}
/**
* Compares two certificates, returning false if any data
* differs between the two.
*
* @param other the object being compared with this one
* @return true iff the certificates are equivalent
*/
if (this == other) {
return(true);
return(false);
return(false);
}
return(false);
}
}
return(true);
}
/**
* Calculates a hash code value for the object. Objects
* which are equal will also have the same hashcode.
*/
public int hashCode() {
int retval = 0;
retval += rawCertInfo[i] * i;
}
return(retval);
}
/**
* Returns a printable representation of the certificate.
*/
throw new NullPointerException("X.509 cert is incomplete");
}
// optional v2, v3 extras
if (issuerUniqueId != null) {
}
if (subjectUniqueId != null) {
}
if (extensions != null) {
try {
+ "DER encoded OCTET string =\n"
}
} else
} catch (Exception e) {
}
}
int i = 1;
}
}
}
}
/**
* Set the certificate attribute.
*
* @params name the name of the Certificate attribute.
* @params val the value of the Certificate attribute.
* @exception CertificateException on invalid attributes.
* @exception IOException on other errors.
*/
throws CertificateException, IOException {
if (attr == 0) {
throw new CertificateException("Attribute name not recognized: "
+ name);
}
// set rawCertInfo to null, so that we are forced to re-encode
rawCertInfo = null;
switch (attr) {
case ATTR_VERSION:
} else {
}
break;
case ATTR_SERIAL:
} else {
}
break;
case ATTR_ALGORITHM:
} else {
}
break;
case ATTR_ISSUER:
} else {
}
break;
case ATTR_VALIDITY:
} else {
}
break;
case ATTR_SUBJECT:
} else {
}
break;
case ATTR_KEY:
} else {
}
break;
case ATTR_ISSUER_ID:
} else {
}
break;
case ATTR_SUBJECT_ID:
} else {
}
break;
case ATTR_EXTENSIONS:
} else {
if (extensions == null)
extensions = new CertificateExtensions();
}
break;
}
}
/**
* Delete the certificate attribute.
*
* @params name the name of the Certificate attribute.
* @exception CertificateException on invalid attributes.
* @exception IOException on other errors.
*/
throws CertificateException, IOException {
if (attr == 0) {
throw new CertificateException("Attribute name not recognized: "
+ name);
}
// set rawCertInfo to null, so that we are forced to re-encode
rawCertInfo = null;
switch (attr) {
case ATTR_VERSION:
} else {
}
break;
case (ATTR_SERIAL):
} else {
}
break;
case (ATTR_ALGORITHM):
} else {
}
break;
case (ATTR_ISSUER):
} else {
}
break;
case (ATTR_VALIDITY):
} else {
}
break;
case (ATTR_SUBJECT):
} else {
}
break;
case (ATTR_KEY):
} else {
}
break;
case (ATTR_ISSUER_ID):
} else {
}
break;
case (ATTR_SUBJECT_ID):
} else {
}
break;
case (ATTR_EXTENSIONS):
extensions = null;
} else {
if (extensions != null)
}
break;
}
}
/**
* Get the certificate attribute.
*
* @params name the name of the Certificate attribute.
*
* @exception CertificateException on invalid attributes.
* @exception IOException on other errors.
*/
throws CertificateException, IOException {
if (attr == 0) {
throw new CertificateParsingException(
"Attribute name not recognized: " + name);
}
switch (attr) { // frequently used attributes first
case (ATTR_EXTENSIONS):
return(extensions);
} else {
if (extensions == null) {
return null;
} else {
}
}
case (ATTR_SUBJECT):
return(subject);
} else {
}
case (ATTR_ISSUER):
return(issuer);
} else {
}
case (ATTR_KEY):
return(pubKey);
} else {
}
case (ATTR_ALGORITHM):
return(algId);
} else {
}
case (ATTR_VALIDITY):
return(interval);
} else {
}
case (ATTR_VERSION):
return(version);
} else {
}
case (ATTR_SERIAL):
return(serialNum);
} else {
}
case (ATTR_ISSUER_ID):
return(issuerUniqueId);
} else {
if (issuerUniqueId == null)
return null;
else
}
case (ATTR_SUBJECT_ID):
return(subjectUniqueId);
} else {
if (subjectUniqueId == null)
return null;
else
}
}
return null;
}
/*
* This routine unmarshals the certificate information.
*/
throws CertificateParsingException, IOException {
throw new CertificateParsingException("signed fields invalid");
}
// Version
}
// Serial number ... an integer
// Algorithm Identifier
// Issuer name
throw new CertificateParsingException(
"Empty issuer DN not allowed in X509Certificates");
}
// validity: SEQUENCE { start date, end date }
// subject name
throw new CertificateParsingException(
"Empty subject DN not allowed in v1 certificate");
}
// public key
// If more data available, make sure version is not v1.
throw new CertificateParsingException(
"no more data allowed for version 1 certificate");
}
} else {
return;
}
// Get the issuerUniqueId if present
return;
}
// Get the subjectUniqueId if present.
return;
}
// Get the extensions.
throw new CertificateParsingException(
"Extensions not allowed in v2 certificate");
}
}
// verify X.509 V3 Certificate
}
/*
* Verify if X.509 V3 Certificate is compliant with RFC 3280.
*/
throws CertificateParsingException, IOException {
// if SubjectName is empty, check for SubjectAlternativeNameExtension
if (extensions == null) {
throw new CertificateParsingException("X.509 Certificate is " +
"incomplete: subject field is empty, and certificate " +
"has no extensions");
}
try {
} catch (IOException e) {
throw new CertificateParsingException("X.509 Certificate is " +
"incomplete: subject field is empty, and " +
"SubjectAlternativeName extension is absent");
}
// SubjectAlternativeName extension is empty or not marked critical
throw new CertificateParsingException("X.509 Certificate is " +
"incomplete: subject field is empty, and " +
"SubjectAlternativeName extension is empty");
} else if (subjectAltNameExt.isCritical() == false) {
throw new CertificateParsingException("X.509 Certificate is " +
"incomplete: SubjectAlternativeName extension MUST " +
"be marked critical when subject field is empty");
}
}
}
/*
* Marshal the contents of a "raw" certificate into a DER sequence.
*/
throws CertificateException, IOException {
// version number, iff not V1
// Encode serial number, issuer signing algorithm, issuer name
// and validity
throw new CertificateParsingException(
"Null issuer DN not allowed in v1 certificate");
// Encode subject (principal) and associated key
throw new CertificateParsingException(
"Null subject DN not allowed in v1 certificate");
// Encode issuerUniqueId & subjectUniqueId.
if (issuerUniqueId != null) {
}
if (subjectUniqueId != null) {
}
// Write all the extensions.
if (extensions != null) {
}
// Wrap the data; encoding of the "raw" cert is now complete.
}
/**
* Returns the integer attribute number for the passed attribute name.
*/
return 0;
}
}
/**
* Set the version number of the certificate.
*
* @params val the Object class value for the Extensions
* @exception CertificateException on invalid data.
*/
if (!(val instanceof CertificateVersion)) {
throw new CertificateException("Version class type invalid.");
}
}
/**
* Set the serial number of the certificate.
*
* @params val the Object class value for the CertificateSerialNumber
* @exception CertificateException on invalid data.
*/
if (!(val instanceof CertificateSerialNumber)) {
throw new CertificateException("SerialNumber class type invalid.");
}
}
/**
* Set the algorithm id of the certificate.
*
* @params val the Object class value for the AlgorithmId
* @exception CertificateException on invalid data.
*/
if (!(val instanceof CertificateAlgorithmId)) {
throw new CertificateException(
"AlgorithmId class type invalid.");
}
}
/**
* Set the issuer name of the certificate.
*
* @params val the Object class value for the issuer
* @exception CertificateException on invalid data.
*/
if (!(val instanceof CertificateIssuerName)) {
throw new CertificateException(
"Issuer class type invalid.");
}
}
/**
* Set the validity interval of the certificate.
*
* @params val the Object class value for the CertificateValidity
* @exception CertificateException on invalid data.
*/
if (!(val instanceof CertificateValidity)) {
throw new CertificateException(
"CertificateValidity class type invalid.");
}
}
/**
* Set the subject name of the certificate.
*
* @params val the Object class value for the Subject
* @exception CertificateException on invalid data.
*/
if (!(val instanceof CertificateSubjectName)) {
throw new CertificateException(
"Subject class type invalid.");
}
}
/**
* Set the public key in the certificate.
*
* @params val the Object class value for the PublicKey
* @exception CertificateException on invalid data.
*/
if (!(val instanceof CertificateX509Key)) {
throw new CertificateException(
"Key class type invalid.");
}
}
/**
* Set the Issuer Unique Identity in the certificate.
*
* @params val the Object class value for the IssuerUniqueId
* @exception CertificateException
*/
throw new CertificateException("Invalid version");
}
if (!(val instanceof CertificateIssuerUniqueIdentity)) {
throw new CertificateException(
"IssuerUniqueId class type invalid.");
}
}
/**
* Set the Subject Unique Identity in the certificate.
*
* @params val the Object class value for the SubjectUniqueId
* @exception CertificateException
*/
throw new CertificateException("Invalid version");
}
if (!(val instanceof CertificateSubjectUniqueIdentity)) {
throw new CertificateException(
"SubjectUniqueId class type invalid.");
}
}
/**
* Set the extensions in the certificate.
*
* @params val the Object class value for the Extensions
* @exception CertificateException
*/
throw new CertificateException("Invalid version");
}
if (!(val instanceof CertificateExtensions)) {
throw new CertificateException(
"Extensions class type invalid.");
}
}
}