/* * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * KeySelector which would retrieve the X509Certificate out of the * KeyInfo element and return the public key. * NOTE: If there is an X509CRL in the KeyInfo element, then revoked * certificate will be ignored.
*/ staticclass RawX509KeySelector extends KeySelector {
public KeySelectorResult select(KeyInfo keyInfo,
KeySelector.Purpose purpose,
AlgorithmMethod method,
XMLCryptoContext context) throws KeySelectorException { if (keyInfo == null) { thrownew KeySelectorException("Null KeyInfo object!");
} // search for X509Data in keyinfo for (XMLStructure kiType : keyInfo.getContent()) { if (kiType instanceof X509Data) {
X509Data xd = (X509Data) kiType;
Object[] entries = xd.getContent().toArray();
X509CRL crl = null; // Looking for CRL before finding certificates for (int i = 0; (i<entries.length&&crl != null); i++) { if (entries[i] instanceof X509CRL) {
crl = (X509CRL) entries[i];
}
} boolean hasCRL = false; for (Object o : xd.getContent()) { // skip non-X509Certificate entries if (o instanceof X509Certificate) { if ((purpose != KeySelector.Purpose.VERIFY) &&
(crl != null) &&
crl.isRevoked((X509Certificate)o)) { continue;
} else { returnnew SimpleKSResult
(((X509Certificate)o).getPublicKey());
}
}
}
}
} thrownew KeySelectorException("No X509Certificate found!");
}
}
/** * KeySelector which would retrieve the public key out of the * KeyValue element and return it. * NOTE: If the key algorithm doesn't match signature algorithm, * then the public key will be ignored.
*/ staticclass KeyValueKeySelector extends KeySelector { public KeySelectorResult select(KeyInfo keyInfo,
KeySelector.Purpose purpose,
AlgorithmMethod method,
XMLCryptoContext context) throws KeySelectorException { if (keyInfo == null) { thrownew KeySelectorException("Null KeyInfo object!");
}
SignatureMethod sm = (SignatureMethod) method;
for (XMLStructure xmlStructure : keyInfo.getContent()) { if (xmlStructure instanceof KeyValue) {
PublicKey pk = null; try {
pk = ((KeyValue)xmlStructure).getPublicKey();
} catch (KeyException ke) { thrownew KeySelectorException(ke);
} // make sure algorithm is compatible with method if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) { returnnew SimpleKSResult(pk);
}
}
} thrownew KeySelectorException("No KeyValue element found!");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.