Showing the changes to java/pkg/sun/security/provider/certpath/Vertex.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,239 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package sun.security.provider.certpath; | |
| 27 | + | |
| 28 | +import sun.security.util.Debug; | |
| 29 | + | |
| 30 | +import java.security.cert.Certificate; | |
| 31 | +import java.security.cert.CertificateException; | |
| 32 | +import java.security.cert.X509Certificate; | |
| 33 | + | |
| 34 | +import sun.security.x509.AuthorityKeyIdentifierExtension; | |
| 35 | +import sun.security.x509.KeyIdentifier; | |
| 36 | +import sun.security.x509.SubjectKeyIdentifierExtension; | |
| 37 | +import sun.security.x509.X509CertImpl; | |
| 38 | + | |
| 39 | +/* | |
| 40 | + * This class represents a vertex in the adjacency list. A | |
| 41 | + * vertex in the builder's view is just a distinguished name | |
| 42 | + * in the directory. The Vertex contains a certificate | |
| 43 | + * along an attempted certification path, along with a pointer | |
| 44 | + * to a list of certificates that followed this one in various | |
| 45 | + * attempted certification paths. | |
| 46 | + * | |
| 47 | + * @author Sean Mullan | |
| 48 | + * @since 1.4 | |
| 49 | + */ | |
| 50 | +public class Vertex { | |
| 51 | + | |
| 52 | + private static final Debug debug = Debug.getInstance("certpath"); | |
| 53 | + private Certificate cert; | |
| 54 | + private int index; | |
| 55 | + private Throwable throwable; | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * Constructor; creates vertex with index of -1 | |
| 59 | + * Use setIndex method to set another index. | |
| 60 | + * | |
| 61 | + * @param cert Certificate associated with vertex | |
| 62 | + */ | |
| 63 | + Vertex(Certificate cert) { | |
| 64 | + this.cert = cert; | |
| 65 | + this.index = -1; | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * return the certificate for this vertex | |
| 70 | + * | |
| 71 | + * @returns Certificate | |
| 72 | + */ | |
| 73 | + public Certificate getCertificate() { | |
| 74 | + return cert; | |
| 75 | + } | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * get the index for this vertex, where the index is the row of the | |
| 79 | + * adjacency list that contains certificates that could follow this | |
| 80 | + * certificate. | |
| 81 | + * | |
| 82 | + * @returns int index for this vertex, or -1 if no following certificates. | |
| 83 | + */ | |
| 84 | + public int getIndex() { | |
| 85 | + return index; | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * set the index for this vertex, where the index is the row of the | |
| 90 | + * adjacency list that contains certificates that could follow this | |
| 91 | + * certificate. | |
| 92 | + * | |
| 93 | + * @param ndx int index for vertex, or -1 if no following certificates. | |
| 94 | + */ | |
| 95 | + void setIndex(int ndx) { | |
| 96 | + index = ndx; | |
| 97 | + } | |
| 98 | + | |
| 99 | + /** | |
| 100 | + * return the throwable associated with this vertex; | |
| 101 | + * returns null if none. | |
| 102 | + * | |
| 103 | + * @returns Throwable | |
| 104 | + */ | |
| 105 | + public Throwable getThrowable() { | |
| 106 | + return throwable; | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * set throwable associated with this vertex; default value is null. | |
| 111 | + * | |
| 112 | + * @param throwable Throwable associated with this vertex | |
| 113 | + * (or null) | |
| 114 | + */ | |
| 115 | + void setThrowable(Throwable throwable) { | |
| 116 | + this.throwable = throwable; | |
| 117 | + } | |
| 118 | + | |
| 119 | + /** | |
| 120 | + * Return full string representation of vertex | |
| 121 | + * | |
| 122 | + * @returns String representation of vertex | |
| 123 | + */ | |
| 124 | + public String toString() { | |
| 125 | + return certToString() + throwableToString() + indexToString(); | |
| 126 | + } | |
| 127 | + | |
| 128 | + /** | |
| 129 | + * Return string representation of this vertex's | |
| 130 | + * certificate information. | |
| 131 | + * | |
| 132 | + * @returns String representation of certificate info | |
| 133 | + */ | |
| 134 | + public String certToString() { | |
| 135 | + String out = ""; | |
| 136 | + if (cert == null || ! (cert instanceof X509Certificate)) | |
| 137 | + return "Cert: Not an X509Certificate\n"; | |
| 138 | + | |
| 139 | + X509CertImpl x509Cert = null; | |
| 140 | + try { | |
| 141 | + x509Cert = X509CertImpl.toImpl((X509Certificate)cert); | |
| 142 | + } catch (CertificateException ce) { | |
| 143 | + if (debug != null) { | |
| 144 | + debug.println("Vertex.certToString() unexpected exception"); | |
| 145 | + ce.printStackTrace(); | |
| 146 | + } | |
| 147 | + return out; | |
| 148 | + } | |
| 149 | + | |
| 150 | + out = "Issuer: " + x509Cert.getIssuerX500Principal() + "\n"; | |
| 151 | + out = out + "Subject: " + x509Cert.getSubjectX500Principal() + "\n"; | |
| 152 | + out = out + "SerialNum: " + (x509Cert.getSerialNumber()).toString(16) + "\n"; | |
| 153 | + out = out + "Expires: " + x509Cert.getNotAfter().toString() + "\n"; | |
| 154 | + boolean[] iUID = x509Cert.getIssuerUniqueID(); | |
| 155 | + if (iUID != null) { | |
| 156 | + out = out + "IssuerUID: "; | |
| 157 | + for (int i=0; i < iUID.length; i++) { | |
| 158 | + out = out + (iUID[i]?1:0); | |
| 159 | + } | |
| 160 | + out = out + "\n"; | |
| 161 | + } | |
| 162 | + boolean[] sUID = x509Cert.getSubjectUniqueID(); | |
| 163 | + if (sUID != null) { | |
| 164 | + out = out + "SubjectUID: "; | |
| 165 | + for (int i=0; i< sUID.length; i++) { | |
| 166 | + out = out + (sUID[i]?1:0); | |
| 167 | + } | |
| 168 | + out = out + "\n"; | |
| 169 | + } | |
| 170 | + SubjectKeyIdentifierExtension sKeyID = null; | |
| 171 | + try { | |
| 172 | + sKeyID = x509Cert.getSubjectKeyIdentifierExtension(); | |
| 173 | + if (sKeyID != null) { | |
| 174 | + KeyIdentifier keyID = (KeyIdentifier)sKeyID.get(sKeyID.KEY_ID); | |
| 175 | + out = out + "SubjKeyID: " + keyID.toString(); | |
| 176 | + } | |
| 177 | + } catch (Exception e) { | |
| 178 | + if (debug != null) { | |
| 179 | + debug.println("Vertex.certToString() unexpected exception"); | |
| 180 | + e.printStackTrace(); | |
| 181 | + } | |
| 182 | + } | |
| 183 | + AuthorityKeyIdentifierExtension aKeyID = null; | |
| 184 | + try { | |
| 185 | + aKeyID = x509Cert.getAuthorityKeyIdentifierExtension(); | |
| 186 | + if (aKeyID != null) { | |
| 187 | + KeyIdentifier keyID = (KeyIdentifier)aKeyID.get(aKeyID.KEY_ID); | |
| 188 | + out = out + "AuthKeyID: " + keyID.toString(); | |
| 189 | + } | |
| 190 | + } catch (Exception e) { | |
| 191 | + if (debug != null) { | |
| 192 | + debug.println("Vertex.certToString() 2 unexpected exception"); | |
| 193 | + e.printStackTrace(); | |
| 194 | + } | |
| 195 | + } | |
| 196 | + return out; | |
| 197 | + } | |
| 198 | + | |
| 199 | + /** | |
| 200 | + * return Vertex throwable as String compatible with | |
| 201 | + * the way toString returns other information | |
| 202 | + * | |
| 203 | + * @returns String form of exception (or "none") | |
| 204 | + */ | |
| 205 | + public String throwableToString() { | |
| 206 | + String out = "Exception: "; | |
| 207 | + if (throwable != null) | |
| 208 | + out = out + throwable.toString(); | |
| 209 | + else | |
| 210 | + out = out + "null"; | |
| 211 | + out = out + "\n"; | |
| 212 | + return out; | |
| 213 | + } | |
| 214 | + | |
| 215 | + /** | |
| 216 | + * return Vertex index as String compatible with | |
| 217 | + * the way other Vertex.xToString() methods display | |
| 218 | + * information. | |
| 219 | + * | |
| 220 | + * @returns String form of index as "Last cert? [Yes/No] | |
| 221 | + */ | |
| 222 | + public String moreToString() { | |
| 223 | + String out = "Last cert? "; | |
| 224 | + out = out + ((index == -1)?"Yes":"No"); | |
| 225 | + out = out + "\n"; | |
| 226 | + return out; | |
| 227 | + } | |
| 228 | + | |
| 229 | + /** | |
| 230 | + * return Vertex index as String compatible with | |
| 231 | + * the way other Vertex.xToString() methods displays other information. | |
| 232 | + * | |
| 233 | + * @returns String form of index as "Index: [numeric index]" | |
| 234 | + */ | |
| 235 | + public String indexToString() { | |
| 236 | + String out = "Index: " + index + "\n"; | |
| 237 | + return out; | |
| 238 | + } | |
| 239 | +} | |