use of com.sun.org.apache.xml.internal.security.keys.content.X509Data in project jdk8u_jdk by JetBrains.
the class XMLSignature method addKeyInfo.
/**
* Add an X509 Certificate to the KeyInfo. This will include the whole cert
* inside X509Data/X509Certificate tags.
*
* @param cert Certificate to be included. This should be the certificate of
* the key that was used to sign.
* @throws XMLSecurityException
*/
public void addKeyInfo(X509Certificate cert) throws XMLSecurityException {
X509Data x509data = new X509Data(this.doc);
x509data.addCertificate(cert);
this.getKeyInfo().add(x509data);
}
use of com.sun.org.apache.xml.internal.security.keys.content.X509Data in project jdk8u_jdk by JetBrains.
the class PrivateKeyResolver method resolveX509Data.
private PrivateKey resolveX509Data(Element element, String baseURI) {
log.log(java.util.logging.Level.FINE, "Can I resolve X509Data?");
try {
X509Data x509Data = new X509Data(element, baseURI);
int len = x509Data.lengthSKI();
for (int i = 0; i < len; i++) {
XMLX509SKI x509SKI = x509Data.itemSKI(i);
PrivateKey privKey = resolveX509SKI(x509SKI);
if (privKey != null) {
return privKey;
}
}
len = x509Data.lengthIssuerSerial();
for (int i = 0; i < len; i++) {
XMLX509IssuerSerial x509Serial = x509Data.itemIssuerSerial(i);
PrivateKey privKey = resolveX509IssuerSerial(x509Serial);
if (privKey != null) {
return privKey;
}
}
len = x509Data.lengthSubjectName();
for (int i = 0; i < len; i++) {
XMLX509SubjectName x509SubjectName = x509Data.itemSubjectName(i);
PrivateKey privKey = resolveX509SubjectName(x509SubjectName);
if (privKey != null) {
return privKey;
}
}
len = x509Data.lengthCertificate();
for (int i = 0; i < len; i++) {
XMLX509Certificate x509Cert = x509Data.itemCertificate(i);
PrivateKey privKey = resolveX509Certificate(x509Cert);
if (privKey != null) {
return privKey;
}
}
} catch (XMLSecurityException e) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
} catch (KeyStoreException e) {
log.log(java.util.logging.Level.FINE, "KeyStoreException", e);
}
return null;
}
use of com.sun.org.apache.xml.internal.security.keys.content.X509Data in project jdk8u_jdk by JetBrains.
the class X509IssuerSerialResolver method engineLookupResolveX509Certificate.
/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
X509Data x509data = null;
try {
x509data = new X509Data(element, baseURI);
} catch (XMLSignatureException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "I can't");
}
return null;
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "I can't");
}
return null;
}
if (!x509data.containsIssuerSerial()) {
return null;
}
try {
if (storage == null) {
Object[] exArgs = { Constants._TAG_X509ISSUERSERIAL };
KeyResolverException ex = new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "", ex);
}
throw ex;
}
int noOfISS = x509data.lengthIssuerSerial();
Iterator<Certificate> storageIterator = storage.getIterator();
while (storageIterator.hasNext()) {
X509Certificate cert = (X509Certificate) storageIterator.next();
XMLX509IssuerSerial certSerial = new XMLX509IssuerSerial(element.getOwnerDocument(), cert);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Found Certificate Issuer: " + certSerial.getIssuerName());
log.log(java.util.logging.Level.FINE, "Found Certificate Serial: " + certSerial.getSerialNumber().toString());
}
for (int i = 0; i < noOfISS; i++) {
XMLX509IssuerSerial xmliss = x509data.itemIssuerSerial(i);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Found Element Issuer: " + xmliss.getIssuerName());
log.log(java.util.logging.Level.FINE, "Found Element Serial: " + xmliss.getSerialNumber().toString());
}
if (certSerial.equals(xmliss)) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "match !!! ");
}
return cert;
}
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "no match...");
}
}
}
return null;
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
}
throw new KeyResolverException("generic.EmptyMessage", ex);
}
}
use of com.sun.org.apache.xml.internal.security.keys.content.X509Data in project jdk8u_jdk by JetBrains.
the class KeyUtils method prinoutKeyInfo.
/**
* Method prinoutKeyInfo
*
* @param ki
* @param os
* @throws XMLSecurityException
*/
public static void prinoutKeyInfo(KeyInfo ki, PrintStream os) throws XMLSecurityException {
for (int i = 0; i < ki.lengthKeyName(); i++) {
KeyName x = ki.itemKeyName(i);
os.println("KeyName(" + i + ")=\"" + x.getKeyName() + "\"");
}
for (int i = 0; i < ki.lengthKeyValue(); i++) {
KeyValue x = ki.itemKeyValue(i);
PublicKey pk = x.getPublicKey();
os.println("KeyValue Nr. " + i);
os.println(pk);
}
for (int i = 0; i < ki.lengthMgmtData(); i++) {
MgmtData x = ki.itemMgmtData(i);
os.println("MgmtData(" + i + ")=\"" + x.getMgmtData() + "\"");
}
for (int i = 0; i < ki.lengthX509Data(); i++) {
X509Data x = ki.itemX509Data(i);
os.println("X509Data(" + i + ")=\"" + (x.containsCertificate() ? "Certificate " : "") + (x.containsIssuerSerial() ? "IssuerSerial " : "") + "\"");
}
}
Aggregations