You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2020/05/15 07:03:29 UTC
svn commit: r1877774 - in /santuario/xml-security-java/trunk/src:
main/java/org/apache/xml/security/keys/content/x509/
test/java/org/apache/xml/security/test/dom/keys/content/x509/
Author: coheigea
Date: Fri May 15 07:03:29 2020
New Revision: 1877774
URL: http://svn.apache.org/viewvc?rev=1877774&view=rev
Log:
Some keys/x509 refactoring
Added:
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SubjectNameTest.java
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509CertificateTest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509IssuerSerialTest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SKITest.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java?rev=1877774&r1=1877773&r2=1877774&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Certificate.java Fri May 15 07:03:29 2020
@@ -100,14 +100,7 @@ public class XMLX509Certificate extends
try (InputStream is = new ByteArrayInputStream(certbytes)) {
CertificateFactory certFact =
CertificateFactory.getInstance(XMLX509Certificate.JCA_CERT_ID);
- X509Certificate cert =
- (X509Certificate) certFact.generateCertificate(is);
-
- if (cert != null) {
- return cert;
- }
-
- return null;
+ return (X509Certificate) certFact.generateCertificate(is);
} catch (CertificateException | IOException ex) {
throw new XMLSecurityException(ex);
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java?rev=1877774&r1=1877773&r2=1877774&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/keys/content/x509/XMLX509Digest.java Fri May 15 07:03:29 2020
@@ -113,17 +113,17 @@ public class XMLX509Digest extends Signa
public static byte[] getDigestBytesFromCert(X509Certificate cert, String algorithmURI) throws XMLSecurityException {
String jcaDigestAlgorithm = JCEMapper.translateURItoJCEID(algorithmURI);
if (jcaDigestAlgorithm == null) {
- Object[] exArgs = { algorithmURI };
- throw new XMLSecurityException("XMLX509Digest.UnknownDigestAlgorithm", exArgs);
+ Object[] exArgs = {algorithmURI};
+ throw new XMLSecurityException("XMLX509Digest.UnknownDigestAlgorithm", exArgs);
}
try {
- MessageDigest md = MessageDigest.getInstance(jcaDigestAlgorithm);
- return md.digest(cert.getEncoded());
- } catch (Exception e) {
- Object[] exArgs = { jcaDigestAlgorithm };
- throw new XMLSecurityException("XMLX509Digest.FailedDigest", exArgs);
- }
+ MessageDigest md = MessageDigest.getInstance(jcaDigestAlgorithm);
+ return md.digest(cert.getEncoded());
+ } catch (Exception e) {
+ Object[] exArgs = {jcaDigestAlgorithm};
+ throw new XMLSecurityException("XMLX509Digest.FailedDigest", exArgs);
+ }
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509CertificateTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509CertificateTest.java?rev=1877774&r1=1877773&r2=1877774&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509CertificateTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509CertificateTest.java Fri May 15 07:03:29 2020
@@ -20,7 +20,10 @@ package org.apache.xml.security.test.dom
import java.io.File;
import java.io.FileInputStream;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import org.apache.xml.security.test.dom.TestUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -28,6 +31,8 @@ import org.apache.xml.security.keys.cont
import org.apache.xml.security.utils.Constants;
import org.apache.xml.security.utils.XMLUtils;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
/**
* Certificate parsing test.
*
@@ -54,4 +59,27 @@ public class XMLX509CertificateTest {
// System.out.println(cert);
}
+ @org.junit.jupiter.api.Test
+ public void testEqualsAndHashCode() throws Exception {
+ File f = null;
+ if (BASEDIR != null && !"".equals(BASEDIR)) {
+ f = new File(BASEDIR + SEP +
+ "src/test/resources/ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/certs/lugh.crt");
+ } else {
+ f = new File(
+ "src/test/resources/ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/certs/lugh.crt");
+ }
+
+ FileInputStream fis = new FileInputStream(f);
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ X509Certificate cert = (X509Certificate) cf.generateCertificate(fis);
+
+ XMLX509Certificate x509Cert1 = new XMLX509Certificate(TestUtils.newDocument(), cert);
+ XMLX509Certificate x509Cert2 = new XMLX509Certificate(TestUtils.newDocument(), cert);
+
+ assertEquals(x509Cert1, x509Cert2);
+ assertEquals(x509Cert1.hashCode(), x509Cert2.hashCode());
+ }
+
+
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509IssuerSerialTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509IssuerSerialTest.java?rev=1877774&r1=1877773&r2=1877774&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509IssuerSerialTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509IssuerSerialTest.java Fri May 15 07:03:29 2020
@@ -50,4 +50,16 @@ public class XMLX509IssuerSerialTest {
assertEquals("CN=\\#abc123", is.getIssuerName());
// System.out.println(is.getIssuerName());
}
+
+ @org.junit.jupiter.api.Test
+ public void testEqualsHashcode() throws Exception {
+ XMLX509IssuerSerial is1 = new XMLX509IssuerSerial(doc, "1234", 0);
+ assertEquals("1234", is1.getIssuerName());
+
+ XMLX509IssuerSerial is2 = new XMLX509IssuerSerial(doc, "1234", 0);
+ assertEquals("1234", is2.getIssuerName());
+
+ assertEquals(is1, is2);
+ assertEquals(is1.hashCode(), is2.hashCode());
+ }
}
\ No newline at end of file
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SKITest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SKITest.java?rev=1877774&r1=1877773&r2=1877774&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SKITest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SKITest.java Fri May 15 07:03:29 2020
@@ -30,8 +30,11 @@ import java.util.Collection;
import java.util.Collections;
import org.apache.xml.security.keys.content.x509.XMLX509SKI;
+import org.apache.xml.security.test.dom.TestUtils;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* Test bugfix 41892: XML Security 1.4.0 does not build with IBM's JDK
@@ -79,5 +82,15 @@ public class XMLX509SKITest {
Collection<?> certs = cs.getCertificates(xcs);
assertFalse(certs.isEmpty());
+
+ XMLX509SKI xmlx509SKI = new XMLX509SKI(TestUtils.newDocument(), skid);
+ assertNotNull(xmlx509SKI.getSKIBytes());
+
+ XMLX509SKI xmlx509SKI2 = new XMLX509SKI(TestUtils.newDocument(), cert);
+ assertNotNull(xmlx509SKI2.getSKIBytes());
+
+ assertEquals(xmlx509SKI, xmlx509SKI2);
+ assertEquals(xmlx509SKI.hashCode(), xmlx509SKI2.hashCode());
+
}
}
Added: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SubjectNameTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SubjectNameTest.java?rev=1877774&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SubjectNameTest.java (added)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/dom/keys/content/x509/XMLX509SubjectNameTest.java Fri May 15 07:03:29 2020
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.dom.keys.content.x509;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+
+import org.apache.xml.security.keys.content.x509.XMLX509SubjectName;
+import org.apache.xml.security.test.dom.TestUtils;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Certificate parsing test.
+ *
+ */
+public class XMLX509SubjectNameTest {
+
+ private static final String BASEDIR =
+ System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
+ private static final String SEP = System.getProperty("file.separator");
+
+ @org.junit.jupiter.api.Test
+ public void testEqualsAndHashCode() throws Exception {
+ File f = null;
+ if (BASEDIR != null && !"".equals(BASEDIR)) {
+ f = new File(BASEDIR + SEP +
+ "src/test/resources/ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/certs/lugh.crt");
+ } else {
+ f = new File(
+ "src/test/resources/ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/certs/lugh.crt");
+ }
+
+ FileInputStream fis = new FileInputStream(f);
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ X509Certificate cert = (X509Certificate) cf.generateCertificate(fis);
+
+ XMLX509SubjectName x509SubjectName1 = new XMLX509SubjectName(TestUtils.newDocument(), cert);
+ assertNotNull(x509SubjectName1.getSubjectName());
+ XMLX509SubjectName x509SubjectName2 = new XMLX509SubjectName(TestUtils.newDocument(), cert);
+
+ assertEquals(x509SubjectName1, x509SubjectName2);
+ assertEquals(x509SubjectName1.hashCode(), x509SubjectName2.hashCode());
+ }
+
+
+}