Search in sources :

Example 6 with BigInt

use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.

the class PresenceServerExtension method encodeThis.

public void encodeThis() throws IOException {
    try (DerOutputStream out = new DerOutputStream()) {
        DerOutputStream temp = new DerOutputStream();
        temp.putInteger(new BigInt(mVersion));
        temp.putOctetString(mStreetAddress.getBytes());
        temp.putOctetString(mTelephoneNumber.getBytes());
        temp.putOctetString(mRFC822Name.getBytes());
        temp.putOctetString(mID.getBytes());
        temp.putOctetString(mHostName.getBytes());
        temp.putInteger(new BigInt(mPortNumber));
        temp.putInteger(new BigInt(mMaxUsers));
        temp.putInteger(new BigInt(mServiceLevel));
        out.write(DerValue.tag_Sequence, temp);
        this.extensionValue = out.toByteArray();
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt)

Example 7 with BigInt

use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.

the class PKCS10 method encodeAndSign.

/**
 * Create the signed certificate request. This will later be
 * retrieved in either string or binary format.
 *
 * @param requester identifies the signer (by X.500 name)
 *            and provides the private key used to sign.
 * @exception IOException on errors.
 * @exception CertificateException on certificate handling errors.
 * @exception SignatureException on signature handling errors.
 */
public void encodeAndSign(X500Signer requester) throws CertificateException, IOException, SignatureException {
    DerOutputStream out, scratch;
    byte[] certificateRequestInfo;
    byte[] sig;
    if (certificateRequest != null)
        throw new SignatureException("request is already signed");
    subject = requester.getSigner();
    /*
         * Encode cert request info, wrap in a sequence for signing
         */
    scratch = new DerOutputStream();
    // version zero
    scratch.putInteger(new BigInt(0));
    // X.500 name
    subject.encode(scratch);
    // public key
    subjectPublicKeyInfo.encode(scratch);
    attributeSet.encode(scratch);
    out = new DerOutputStream();
    // wrap it!
    out.write(DerValue.tag_Sequence, scratch);
    certificateRequestInfo = out.toByteArray();
    scratch = out;
    /*
         * Sign it ...
         */
    requester.update(certificateRequestInfo, 0, certificateRequestInfo.length);
    sig = requester.sign();
    /*
         * Build guts of SIGNED macro
         */
    // sig algorithm
    requester.getAlgorithmId().encode(scratch);
    // sig
    scratch.putBitString(sig);
    /*
         * Wrap those guts in a sequence
         */
    out = new DerOutputStream();
    out.write(DerValue.tag_Sequence, scratch);
    certificateRequest = out.toByteArray();
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt) SignatureException(java.security.SignatureException)

Example 8 with BigInt

use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.

the class CertificateVersion method encode.

/**
 * Encode the CertificateVersion period in DER form to the stream.
 *
 * @param out the OutputStream to marshal the contents to.
 * @exception IOException on errors.
 */
@Override
public void encode(OutputStream out) throws IOException {
    // Nothing for default
    if (version == V1) {
        return;
    }
    try (DerOutputStream tmp = new DerOutputStream();
        DerOutputStream seq = new DerOutputStream()) {
        tmp.putInteger(new BigInt(version));
        seq.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0), tmp);
        out.write(seq.toByteArray());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt)

Example 9 with BigInt

use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.

the class BasicConstraintsExtension method encodeThis.

// Encode this extension value
private void encodeThis() throws IOException {
    try (DerOutputStream out = new DerOutputStream()) {
        DerOutputStream tmp = new DerOutputStream();
        if (ca) {
            tmp.putBoolean(ca);
        }
        if (pathLen >= 0) {
            tmp.putInteger(new BigInt(pathLen));
        }
        out.write(DerValue.tag_Sequence, tmp);
        this.extensionValue = out.toByteArray();
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt)

Example 10 with BigInt

use of org.mozilla.jss.netscape.security.util.BigInt in project jss by dogtagpki.

the class PKCS7 method getCertificate.

/**
 * Returns the X.509 certificate listed in this PKCS7 block
 * which has a matching serial number and Issuer name, or
 * null if one is not found.
 *
 * @param serial the serial number of the certificate to retrieve.
 * @param name the Distinguished Name of the Issuer.
 */
public X509Certificate getCertificate(BigInt serial, X500Name name) {
    for (int i = 0; i < certificates.length; i++) {
        X509Certificate cert = certificates[i];
        X500Name thisName = (X500Name) cert.getIssuerDN();
        BigInteger tmpSerial = cert.getSerialNumber();
        BigInt thisSerial = new BigInt(tmpSerial);
        if (serial.equals(thisSerial) && name.equals(thisName)) {
            return cert;
        }
    }
    return null;
}
Also used : BigInt(org.mozilla.jss.netscape.security.util.BigInt) BigInteger(java.math.BigInteger) X500Name(org.mozilla.jss.netscape.security.x509.X500Name) X509Certificate(java.security.cert.X509Certificate)

Aggregations

BigInt (org.mozilla.jss.netscape.security.util.BigInt)17 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)13 DerValue (org.mozilla.jss.netscape.security.util.DerValue)3 IOException (java.io.IOException)2 AlgorithmId (org.mozilla.jss.netscape.security.x509.AlgorithmId)2 BigInteger (java.math.BigInteger)1 SignatureException (java.security.SignatureException)1 CRLException (java.security.cert.CRLException)1 X509Certificate (java.security.cert.X509Certificate)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 MGF1ParameterSpec (java.security.spec.MGF1ParameterSpec)1 PSSParameterSpec (java.security.spec.PSSParameterSpec)1 DerInputStream (org.mozilla.jss.netscape.security.util.DerInputStream)1 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)1 CertificateX509Key (org.mozilla.jss.netscape.security.x509.CertificateX509Key)1 X500Name (org.mozilla.jss.netscape.security.x509.X500Name)1 X509Key (org.mozilla.jss.netscape.security.x509.X509Key)1 PK11ECPublicKey (org.mozilla.jss.pkcs11.PK11ECPublicKey)1