Search in sources :

Example 6 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.

the class Certificate method main.

public static void main(String[] argv) {
    try {
        if (argv.length > 2 || argv.length < 1) {
            System.out.println("Usage: Certificate <dbdir> [<certfile>]");
            System.exit(0);
        }
        CryptoManager.initialize(argv[0]);
        CryptoManager cm = CryptoManager.getInstance();
        Certificate cert;
        // read in a cert
        FileInputStream fis = new FileInputStream(argv[1]);
        try (BufferedInputStream bis = new BufferedInputStream(fis)) {
            cert = (Certificate) Certificate.getTemplate().decode(bis);
        }
        CertificateInfo info = cert.getInfo();
        info.print(System.out);
        // X509Certificate hardcore = cm.findCertByNickname("Hardcore");
        // PublicKey key = hardcore.getPublicKey();
        cert.verify();
        System.out.println("verified");
        FileOutputStream fos = new FileOutputStream("certinfo.der");
        info.encode(fos);
        fos.close();
        // make a new public key
        CryptoToken token = cm.getInternalKeyStorageToken();
        KeyPairGenerator kpg = token.getKeyPairGenerator(KeyPairAlgorithm.RSA);
        kpg.initialize(512);
        System.out.println("Generating a new key pair...");
        KeyPair kp = kpg.genKeyPair();
        System.out.println("Generated key pair");
        // set the certificate's public key
        info.setSubjectPublicKeyInfo(kp.getPublic());
        // increment serial number
        int newSerial = info.getSerialNumber().intValue() + 1;
        info.setSerialNumber(new INTEGER(newSerial));
        // make new Name
        Name name = new Name();
        name.addCommonName("Stra\u00dfenverk\u00e4ufer 'R' Us");
        name.addCountryName("US");
        name.addOrganizationName("Some Corporation");
        name.addOrganizationalUnitName("some org unit?");
        name.addLocalityName("Silicon Valley");
        name.addStateOrProvinceName("California");
        info.setIssuer(name);
        info.setSubject(name);
        // set validity
        Calendar cal = Calendar.getInstance();
        cal.set(1997, Calendar.APRIL, 1);
        info.setNotBefore(cal.getTime());
        cal.set(2010, Calendar.APRIL, 1);
        info.setNotAfter(cal.getTime());
        System.out.println("About to create a new cert...");
        // create a new cert from this certinfo
        Certificate genCert = new Certificate(info, kp.getPrivate(), SignatureAlgorithm.RSASignatureWithMD5Digest);
        System.out.println("Created new cert");
        genCert.verify();
        System.out.println("Cert verifies!");
        fos = new FileOutputStream("gencert.der");
        genCert.encode(fos);
        fos.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : KeyPair(java.security.KeyPair) CryptoToken(org.mozilla.jss.crypto.CryptoToken) Calendar(java.util.Calendar) CryptoManager(org.mozilla.jss.CryptoManager) KeyPairGenerator(org.mozilla.jss.crypto.KeyPairGenerator) FileInputStream(java.io.FileInputStream) InvalidBERException(org.mozilla.jss.asn1.InvalidBERException) InvalidKeyFormatException(org.mozilla.jss.crypto.InvalidKeyFormatException) SignatureException(java.security.SignatureException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) TokenException(org.mozilla.jss.crypto.TokenException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NotInitializedException(org.mozilla.jss.NotInitializedException) InvalidKeyException(java.security.InvalidKeyException) Name(org.mozilla.jss.pkix.primitive.Name) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) INTEGER(org.mozilla.jss.asn1.INTEGER)

Example 7 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.

the class BodyPartReference method addBodyPartId.

/**
 * Adds a BodyPartID to the bodyPartPath SEQUENCE.
 */
public void addBodyPartId(int id) {
    INTEGER id1 = new INTEGER(id);
    assert (id1.compareTo(BODYIDMAX) <= 0);
    bodyPartPath.addElement(id1);
}
Also used : INTEGER(org.mozilla.jss.asn1.INTEGER)

Example 8 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.

the class CertificateInfo method encode.

@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
    SEQUENCE seq = new SEQUENCE();
    if (version != v1) {
        // v1 is the default
        seq.addElement(new EXPLICIT(new Tag(0), new INTEGER(version.getNumber())));
    }
    seq.addElement(serialNumber);
    seq.addElement(signatureAlgId);
    seq.addElement(issuer);
    SEQUENCE validity = new SEQUENCE();
    validity.addElement(encodeValidityDate(notBefore));
    validity.addElement(encodeValidityDate(notAfter));
    seq.addElement(validity);
    seq.addElement(subject);
    seq.addElement(subjectPublicKeyInfo);
    if (issuerUniqueIdentifier != null) {
        seq.addElement(new Tag(1), issuerUniqueIdentifier);
    }
    if (subjectUniqueIdentifier != null) {
        seq.addElement(new Tag(2), subjectUniqueIdentifier);
    }
    if (extensions.size() > 0) {
        seq.addElement(new EXPLICIT(new Tag(3), extensions));
    }
    seq.encode(implicitTag, ostream);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) Tag(org.mozilla.jss.asn1.Tag) EXPLICIT(org.mozilla.jss.asn1.EXPLICIT) INTEGER(org.mozilla.jss.asn1.INTEGER)

Example 9 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.

the class CMCStatusInfoV2 method addBodyPartID.

/**
 * Adds a BodyPartID to the bodyList SEQUENCE.
 */
public void addBodyPartID(int id) {
    INTEGER id1 = new INTEGER(id);
    assert (id1.compareTo(BODYIDMAX) <= 0);
    bodyList.addElement(id1);
}
Also used : INTEGER(org.mozilla.jss.asn1.INTEGER)

Example 10 with org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer

use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer in project jss by dogtagpki.

the class MacData method encode.

@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
    SEQUENCE seq = new SEQUENCE();
    seq.addElement(mac);
    seq.addElement(macSalt);
    if (!macIterationCount.equals(new INTEGER(DEFAULT_ITERATIONS))) {
        // 1 is the default, only include this element if it is not
        // the default
        seq.addElement(macIterationCount);
    }
    seq.encode(implicitTag, ostream);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) INTEGER(org.mozilla.jss.asn1.INTEGER)

Aggregations

Integer (org.jpl7.Integer)19 INTEGER (org.mozilla.jss.asn1.INTEGER)15 BigInteger (java.math.BigInteger)11 Test (org.junit.Test)10 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer)9 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)8 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float)7 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint)7 Map (java.util.Map)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime)6 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time)6