use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class PKCS12Util method createCertBagAttrs.
SET createCertBagAttrs(PKCS12CertInfo certInfo) throws Exception {
SET attrs = new SET();
String friendlyName = certInfo.getFriendlyName();
logger.debug(" Friendly name: " + friendlyName);
SEQUENCE nicknameAttr = new SEQUENCE();
nicknameAttr.addElement(SafeBag.FRIENDLY_NAME);
SET nicknameSet = new SET();
nicknameSet.addElement(new BMPString(friendlyName));
nicknameAttr.addElement(nicknameSet);
attrs.addElement(nicknameAttr);
String trustFlags = certInfo.getTrustFlags();
if (trustFlags != null && trustFlagsEnabled) {
logger.debug(" Trust flags: " + trustFlags);
SEQUENCE trustFlagsAttr = new SEQUENCE();
trustFlagsAttr.addElement(PKCS12.CERT_TRUST_FLAGS_OID);
SET trustFlagsSet = new SET();
trustFlagsSet.addElement(new BMPString(trustFlags));
trustFlagsAttr.addElement(trustFlagsSet);
attrs.addElement(trustFlagsAttr);
}
byte[] keyID = certInfo.getKeyID();
if (keyID != null) {
logger.debug(" Key ID: " + Utils.HexEncode(keyID));
SEQUENCE localKeyAttr = new SEQUENCE();
localKeyAttr.addElement(SafeBag.LOCAL_KEY_ID);
SET localKeySet = new SET();
localKeySet.addElement(new OCTET_STRING(keyID));
localKeyAttr.addElement(localKeySet);
attrs.addElement(localKeyAttr);
}
return attrs;
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class Attribute method encode.
@Override
public void encode(Tag implicit, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(type);
seq.addElement(values);
seq.encode(implicit, ostream);
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class SignerInfo method verifyWithoutAuthenticatedAttributes.
/**
* Verifies that the message digest passed in, when encrypted with the
* given public key, matches the encrypted digest in the SignerInfo.
*/
private void verifyWithoutAuthenticatedAttributes(byte[] messageDigest, OBJECT_IDENTIFIER contentType, PublicKey pubkey) throws NotInitializedException, NoSuchAlgorithmException, InvalidKeyException, TokenException, SignatureException {
if (!contentType.equals(ContentInfo.DATA)) {
// to go into authenticatedAttributes.
throw new SignatureException("Content-Type is not DATA, but there are" + " no authenticated attributes");
}
SignatureAlgorithm sigAlg = SignatureAlgorithm.fromOID(digestEncryptionAlgorithm.getOID());
byte[] toBeVerified;
if (sigAlg.getRawAlg() == SignatureAlgorithm.RSASignature) {
// create DigestInfo structure
SEQUENCE digestInfo = new SEQUENCE();
digestInfo.addElement(new AlgorithmIdentifier(digestAlgorithm.getOID(), null));
digestInfo.addElement(new OCTET_STRING(messageDigest));
toBeVerified = ASN1Util.encode(digestInfo);
} else {
toBeVerified = messageDigest;
}
CryptoToken token = CryptoManager.getInstance().getInternalCryptoToken();
Signature sig = token.getSignatureContext(sigAlg);
sig.initVerify(pubkey);
sig.update(toBeVerified);
if (sig.verify(encryptedDigest.toByteArray())) {
// success
return;
} else {
throw new SignatureException("Encrypted message digest parameter does not " + "match encrypted digest in SignerInfo");
}
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class SignerInfo method encode.
@Override
public void encode(Tag tag, OutputStream ostream) throws IOException {
SEQUENCE sequence = new SEQUENCE();
sequence.addElement(version);
sequence.addElement(issuerAndSerialNumber);
sequence.addElement(digestAlgorithm);
if (authenticatedAttributes != null) {
sequence.addElement(new Tag(0), authenticatedAttributes);
}
sequence.addElement(digestEncryptionAlgorithm);
sequence.addElement(encryptedDigest);
if (unauthenticatedAttributes != null) {
sequence.addElement(new Tag(1), unauthenticatedAttributes);
}
sequence.encode(tag, ostream);
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class CMCStatusInfoV2 method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
seq.addElement(status);
seq.addElement(bodyList);
if (statusString != null) {
seq.addElement(statusString);
}
if (otherInfo != null) {
seq.addElement(otherInfo);
}
seq.encode(implicitTag, ostream);
}
Aggregations