Pour enregistrer votre certificat d'attribut dans un fichier PEM, vous pouvez utiliser JcaPEMWriter
ainsi:
// save the Attribute Certificate to attcert.pem file
JcaPEMWriter writer = new JcaPEMWriter(new FileWriter("attcert.pem"));
writer.writeObject(att);
writer.close();
Le fichier contiendra une teneur en base64, comme ceci:
-----BEGIN ATTRIBUTE CERTIFICATE-----
MIIBvzCCASgCAQEwZ6BlMGCkXjBcMQswCQYDVQQGEwJBVTEoMCYGA1UECgwfVGhl
IExlZ2lvbiBvZiB0aGUgQm91bmN5IENhc3RsZTEjMCEGA1UECwwaQm91bmN5IFBy
aW1hcnkgQ2VydGlmaWNhdGUCAQKgYjBgpF4wXDELMAkGA1UEBhMCQVUxKDAmBgNV
BAoMH1RoZSBMZWdpb24gb2YgdGhlIEJvdW5jeSBDYXN0bGUxIzAhBgNVBAsMGkJv
dW5jeSBQcmltYXJ5IENlcnRpZmljYXRlMA0GCSqGSIb3DQEBBQUAAgF7MCIYDzIw
MTcwNzA2MTE1MDExWhgPMjAxNzA3MDYxMTUxNTFaMCAwHgYDVQRIMRcwFaEThhFp
ZDovL0RBVTEyMzQ1Njc4OTANBgkqhkiG9w0BAQUFAAOBgQBy3epbynwILi/H0DkQ
UXDgIWXXN5oRQem9DJ2AhYl6JHeKOk3ML87axq+ukWYjZoo3eP2rIxuDU6jWRak1
+n92KLsc/zSFaAdxxYjXQbjTpqEafvEea4QPd4PfPHA9nd4QNKox4H1lNhDeyqtP
B4iU+bkA1bKDo4dnhXVtJaAlkg==
-----END ATTRIBUTE CERTIFICATE-----
Malheureusement, il semble qu'il n'y a pas de commande spécifique dans openssl
pour vérifier le certificat d'attribut (cocher this discussion et this message with no replies - il y a un extended version of openssl
qui semble le supporter, bien que je ne l'ai pas testé).
Mais vous pouvez vérifier la structure ASN.1 en utilisant l'option asn1parse
:
openssl asn1parse -dump -i -in attcert.pem
La sortie sera la structure ASN.1, comme ceci:
0:d=0 hl=4 l= 447 cons: SEQUENCE
4:d=1 hl=4 l= 296 cons: SEQUENCE
8:d=2 hl=2 l= 1 prim: INTEGER :01
11:d=2 hl=2 l= 103 cons: SEQUENCE
13:d=3 hl=2 l= 101 cons: cont [ 0 ]
15:d=4 hl=2 l= 96 cons: SEQUENCE
17:d=5 hl=2 l= 94 cons: cont [ 4 ]
19:d=6 hl=2 l= 92 cons: SEQUENCE
21:d=7 hl=2 l= 11 cons: SET
23:d=8 hl=2 l= 9 cons: SEQUENCE
25:d=9 hl=2 l= 3 prim: OBJECT :countryName
30:d=9 hl=2 l= 2 prim: PRINTABLESTRING :AU
34:d=7 hl=2 l= 40 cons: SET
36:d=8 hl=2 l= 38 cons: SEQUENCE
38:d=9 hl=2 l= 3 prim: OBJECT :organizationName
43:d=9 hl=2 l= 31 prim: UTF8STRING :The Legion of the Bouncy Castle
... and so on
Ou vous pouvez lire la fichier utilisant Bouncy Castle:
import org.bouncycastle.cert.X509AttributeCertificateHolder;
import org.bouncycastle.util.encoders.Base64;
String pem = // read contents from PEM file
// Convert to AC object
byte[] data = Base64.decode(pem.getBytes());
X509AttributeCertificateHolder holder = new X509AttributeCertificateHolder(data);