Search in sources :

Example 6 with ASN1EncodableVector

use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.

the class HelperTest method makeMinimalAtt.

public static Attestation makeMinimalAtt() {
    Attestation att = new Attestation();
    // Our initial version
    att.setVersion(IdentifierAttestation.HIDDEN_IDENTIFIER_VERSION);
    att.setSerialNumber(42);
    // Blank subject info
    att.setSubject("CN=");
    att.setSigningAlgorithm(IdentifierAttestation.DEFAULT_SIGNING_ALGORITHM);
    ASN1EncodableVector dataObject = new ASN1EncodableVector();
    dataObject.add(new DEROctetString("hello world".getBytes()));
    att.setDataObject(new DERSequence(dataObject));
    assertTrue(att.checkValidity());
    return att;
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 7 with ASN1EncodableVector

use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.

the class HelperTest method makeMaximalAtt.

public static IdentifierAttestation makeMaximalAtt(AsymmetricKeyParameter key) throws IOException {
    IdentifierAttestation att = new IdentifierAttestation("205521676", "https://www.deviantart.com/some_user", key);
    att.setSerialNumber(42);
    att.setSigningAlgorithm(IdentifierAttestation.DEFAULT_SIGNING_ALGORITHM);
    att.setIssuer("CN=ALX");
    att.setSmartcontracts(Arrays.asList(42L, 1337L));
    ASN1EncodableVector dataObject = new ASN1EncodableVector();
    dataObject.add(new DEROctetString("hello world".getBytes()));
    dataObject.add(new ASN1Integer(42));
    att.setDataObject(new DERSequence(dataObject));
    assertTrue(att.checkValidity());
    return att;
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 8 with ASN1EncodableVector

use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.

the class HelperTest method makeUnsignedx509Att.

/* the unsigned x509 attestation will have a subject of "CN=0x2042424242424564648" */
public static Attestation makeUnsignedx509Att(AsymmetricKeyParameter key) throws IOException {
    Attestation att = new Attestation();
    // =v3 since counting starts from 0
    att.setVersion(2);
    att.setSerialNumber(42);
    // ECDSA with SHA256 which is needed for a proper x509
    att.setSigningAlgorithm(SignedIdentifierAttestation.ECDSA_WITH_SHA256);
    att.setIssuer("CN=ALX");
    Date now = new Date();
    att.setNotValidBefore(now);
    att.setNotValidAfter(new Date(System.currentTimeMillis() + VALIDITY));
    att.setSubject("CN=0x2042424242424564648");
    SubjectPublicKeyInfo spki = SubjectPublicKeyInfoFactory.createSubjectPublicKeyInfo(key);
    att.setSubjectPublicKeyInfo(spki);
    ASN1EncodableVector extensions = new ASN1EncodableVector();
    extensions.add(Attestation.OID_OCTETSTRING);
    extensions.add(ASN1Boolean.TRUE);
    extensions.add(new DEROctetString("hello world".getBytes()));
    // Double Sequence is needed to be compatible with X509V3
    att.setExtensions(new DERSequence(new DERSequence(extensions)));
    assertTrue(att.isValidX509());
    return att;
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) SubjectPublicKeyInfo(org.bouncycastle.asn1.x509.SubjectPublicKeyInfo) Date(java.util.Date) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 9 with ASN1EncodableVector

use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.

the class CoSignedIdentifierAttestation method constructSignedAttestation.

static byte[] constructSignedAttestation(SignedIdentifierAttestation unsignedAtt, byte[] signature) {
    try {
        byte[] rawAtt = unsignedAtt.getDerEncoding();
        ASN1EncodableVector res = new ASN1EncodableVector();
        res.add(ASN1Primitive.fromByteArray(rawAtt));
        res.add(unsignedAtt.getUnsignedAttestation().getSigningAlgorithm());
        res.add(new DERBitString(signature));
        return new DERSequence(res).getEncoded();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DERBitString(org.bouncycastle.asn1.DERBitString)

Example 10 with ASN1EncodableVector

use of com.github.zhenwei.core.asn1.ASN1EncodableVector in project attestation by TokenScript.

the class DERUtility method encodeSecret.

public static byte[] encodeSecret(BigInteger secret) {
    try {
        ASN1EncodableVector asn1 = new ASN1EncodableVector();
        asn1.add(new DEROctetString(secret.toByteArray()));
        return new DERSequence(asn1).getEncoded();
    } catch (IOException e) {
        throw ExceptionUtil.makeRuntimeException(logger, "Could not encode asn1", e);
    }
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) IOException(java.io.IOException) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Aggregations

ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)391 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)330 DERSequence (org.bouncycastle.asn1.DERSequence)318 DERSequence (com.github.zhenwei.core.asn1.DERSequence)286 IOException (java.io.IOException)104 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)91 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)70 DEROctetString (org.bouncycastle.asn1.DEROctetString)70 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)68 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)57 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)49 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)49 X509Certificate (java.security.cert.X509Certificate)40 BigInteger (java.math.BigInteger)38 DERBitString (org.bouncycastle.asn1.DERBitString)35 DERSet (org.bouncycastle.asn1.DERSet)34 Enumeration (java.util.Enumeration)31 ArrayList (java.util.ArrayList)30 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)28 Iterator (java.util.Iterator)26