Skip to content

Commit 4e18550

Browse files
Enhance Javadoc on several files and other cosmetic fixes
1 parent 81e911b commit 4e18550

File tree

13 files changed

+815
-361
lines changed

13 files changed

+815
-361
lines changed

src/main/java/org/italiangrid/voms/ac/impl/DefaultVOMSACParser.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,51 @@
2727

2828
/**
2929
* Default implementation of the VOMS attribute certificate parsing logic.
30-
*
31-
* @author Andrea Ceccanti
30+
* This class is responsible for extracting and normalizing VOMS attributes
31+
* from a given X.509 certificate chain.
32+
*
33+
* <p>It utilizes a {@link VOMSACLookupStrategy} to locate attribute certificates
34+
* within the provided chain and applies a {@link VOMSAttributesNormalizationStrategy}
35+
* to normalize the extracted attributes.</p>
36+
*
37+
* <p>By default, it uses {@link LeafACLookupStrategy} for lookup and
38+
* {@link LeafVOMSExtensionNormalizationStrategy} for normalization.</p>
3239
*
3340
*/
3441
public class DefaultVOMSACParser implements VOMSACParser {
3542

3643
private final VOMSACLookupStrategy acLookupStrategy;
3744
private final VOMSAttributesNormalizationStrategy acNormalizationStrategy = new LeafVOMSExtensionNormalizationStrategy();
3845

46+
/**
47+
* Creates a new {@code DefaultVOMSACParser} with the default lookup strategy.
48+
* Uses {@link LeafACLookupStrategy} with a {@link NullListener} instance.
49+
*/
3950
public DefaultVOMSACParser() {
4051

4152
this(new LeafACLookupStrategy(NullListener.INSTANCE));
4253
}
4354

55+
/**
56+
* Creates a new {@code DefaultVOMSACParser} with a specified lookup strategy.
57+
* Uses {@link LeafVOMSExtensionNormalizationStrategy} for attribute normalization.
58+
*
59+
* @param strategy the lookup strategy to use for locating attribute certificates
60+
* @throws NullPointerException if the provided strategy is {@code null}
61+
*/
4462
public DefaultVOMSACParser(VOMSACLookupStrategy strategy) {
4563

4664
this.acLookupStrategy = strategy;
4765
}
4866

67+
/**
68+
* Parses and extracts VOMS attributes from a validated X.509 certificate chain.
69+
*
70+
* @param validatedChain the certificate chain to analyze
71+
* @return a list of extracted and normalized {@link VOMSAttribute} objects
72+
* @throws NullPointerException if the provided certificate chain is {@code null}
73+
*/
74+
@Override
4975
public List<VOMSAttribute> parse(X509Certificate[] validatedChain) {
5076

5177
if (validatedChain == null)

src/main/java/org/italiangrid/voms/asn1/VOMSACGenerator.java

Lines changed: 147 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,50 +62,130 @@
6262
import eu.emi.security.authn.x509.proxy.CertificateExtension;
6363

6464
/**
65+
* A generator for VOMS Attribute Certificates (ACs).
66+
* <p>
67+
* This class provides methods for creating VOMS ACs with customizable properties, including
68+
* optional extensions and fake signature bits for testing purposes.
69+
* </p>
6570
*
66-
* This AC generator provides the VOMS AC encoding starting from a set of attributes.
67-
*
68-
* @author Andrea Ceccanti
71+
* <p>
72+
* It uses BouncyCastle for cryptographic operations and supports various extensions required for
73+
* VOMS attribute certificates.
74+
* </p>
6975
*
7076
*/
7177
public class VOMSACGenerator implements VOMSConstants {
7278

79+
/**
80+
* Enumeration defining various properties that can influence the generation of VOMS Attribute
81+
* Certificates.
82+
*/
7383
public enum ACGenerationProperties {
74-
SKIP_AC_CERTS_EXTENSION, FAKE_SIGNATURE_BITS, INCLUDE_FAKE_CRITICAL_EXTENSION, INCLUDE_CRITICAL_NO_REV_AVAIL_EXTENSION, INCLUDE_CRITICAL_AKID_EXTENSION, INCLUDE_EMPTY_AC_CERTS_EXTENSION
84+
85+
// @formatting off
86+
87+
/**
88+
* Skips the inclusion of the AC Certs extension in the generated Attribute Certificate.
89+
* <p>
90+
* This extension normally contains the issuer's certificate chain, which may be omitted
91+
* if the relying party already possesses it.
92+
* </p>
93+
*/
94+
SKIP_AC_CERTS_EXTENSION,
95+
96+
/**
97+
* Generates fake signature bits instead of signing the certificate with a real key.
98+
* <p>
99+
* This is primarily used for testing purposes, as the resulting AC will not be verifiable.
100+
* </p>
101+
*/
102+
FAKE_SIGNATURE_BITS,
103+
104+
/**
105+
* Includes a fake critical extension in the generated Attribute Certificate.
106+
* <p>
107+
* This extension is added for testing scenarios where certificate parsers need to handle
108+
* unknown critical extensions.
109+
* </p>
110+
*/
111+
INCLUDE_FAKE_CRITICAL_EXTENSION,
112+
113+
/**
114+
* Includes the "No Revocation Available" extension as a critical extension.
115+
* <p>
116+
* This extension indicates that no revocation information is available for the AC.
117+
* </p>
118+
*/
119+
INCLUDE_CRITICAL_NO_REV_AVAIL_EXTENSION,
120+
121+
/**
122+
* Includes the Authority Key Identifier (AKID) extension as a critical extension.
123+
* <p>
124+
* The AKID extension helps in linking the AC to its issuer, making it easier for
125+
* verification systems to locate the issuing certificate.
126+
* </p>
127+
*/
128+
INCLUDE_CRITICAL_AKID_EXTENSION,
129+
130+
/**
131+
* Includes an empty AC Certs extension in the generated Attribute Certificate.
132+
* <p>
133+
* This is useful for testing scenarios where the extension is expected but contains no
134+
* actual certificate information.
135+
* </p>
136+
*/
137+
INCLUDE_EMPTY_AC_CERTS_EXTENSION;
138+
// @formatting on
75139
}
76140

141+
/** Default generation properties (none enabled). */
77142
public static final EnumSet<ACGenerationProperties> defaultGenerationProperties =
78143
EnumSet.noneOf(ACGenerationProperties.class);
79144

145+
/**
146+
* A ContentSigner implementation that generates random signature bits.
147+
* <p>
148+
* This is used for testing purposes to create attribute certificates with fake signatures.
149+
* </p>
150+
*/
80151
static class RandomContentSigner implements ContentSigner {
81152

153+
/** The length of the randomly generated signature. */
82154
public static final int SIG_LENGHT = 1024;
83155

84156
ByteArrayOutputStream bos = new ByteArrayOutputStream();
85157

86158
AlgorithmIdentifier sigAlgId;
87159

160+
/**
161+
* Constructs a RandomContentSigner with the given signature algorithm name.
162+
*
163+
* @param sigAlgName the name of the signature algorithm
164+
*/
88165
public RandomContentSigner(String sigAlgName) {
89166

90167
this.sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find(sigAlgName);
91168
}
92169

170+
@Override
93171
public AlgorithmIdentifier getAlgorithmIdentifier() {
94172

95173
return sigAlgId;
96174
}
97175

176+
@Override
98177
public OutputStream getOutputStream() {
99178

100179
return bos;
101180
}
102181

182+
@Override
103183
public byte[] getSignature() {
104184

105185
try {
106186
bos.close();
107187
} catch (IOException e) {
108-
188+
// Ignore
109189
}
110190

111191
Random r = new Random();
@@ -118,12 +198,20 @@ public byte[] getSignature() {
118198

119199
}
120200

201+
/** Fake extension OID used in testing. */
121202
public static final ASN1ObjectIdentifier FAKE_EXT_OID =
122203
new ASN1ObjectIdentifier("1.3.6.1.4.1.8005.100.120.82");
123204

124205
private X509Credential aaCredential;
125206
private ContentSigner signer;
126207

208+
/**
209+
* Retrieves the appropriate ContentSigner based on the provided properties.
210+
*
211+
* @param properties the properties influencing AC generation
212+
* @return a ContentSigner instance
213+
* @throws VOMSError if an error occurs during signer creation
214+
*/
127215
private ContentSigner getSigner(EnumSet<ACGenerationProperties> properties) {
128216

129217
if (signer == null) {
@@ -147,11 +235,24 @@ private ContentSigner getSigner(EnumSet<ACGenerationProperties> properties) {
147235
return signer;
148236
}
149237

238+
/**
239+
* Constructs a VOMSACGenerator with the given credential.
240+
*
241+
* @param aaCredential the attribute authority credential
242+
*/
150243
public VOMSACGenerator(X509Credential aaCredential) {
151244

152245
this.aaCredential = aaCredential;
153246
}
154247

248+
/**
249+
* Builds a VOMS URI.
250+
*
251+
* @param voName the VO name
252+
* @param host the host name
253+
* @param port the port number
254+
* @return a formatted VOMS URI
255+
*/
155256
private String buildVOURI(String voName, String host, int port) {
156257

157258
return String.format("%s://%s:%d", voName, host, port);
@@ -270,20 +371,53 @@ private ASN1Encodable buildTargetsExtensionContent(EnumSet<ACGenerationPropertie
270371
return targetExtensionContent;
271372
}
272373

374+
/**
375+
* Generates a VOMS attribute certificate with the given properties.
376+
*
377+
* @param fqans the list of Fully Qualified Attribute Names (FQANs)
378+
* @param gas the list of generic attributes
379+
* @param targets the list of target restrictions
380+
* @param holderCert the X.509 certificate of the holder
381+
* @param serialNumber the serial number of the AC
382+
* @param notBefore the start of the AC validity period
383+
* @param notAfter the end of the AC validity period
384+
* @param voName the VO name
385+
* @param host the VOMS server hostname
386+
* @param port the VOMS server port
387+
* @return the generated X.509 attribute certificate
388+
* @throws VOMSError if certificate generation fails
389+
*/
273390
public X509AttributeCertificateHolder generateVOMSAttributeCertificate(List<String> fqans,
274391
List<VOMSGenericAttribute> gas, List<String> targets, X509Certificate holderCert,
275392
BigInteger serialNumber, Date notBefore, Date notAfter, String voName, String host,
276-
int port) {
393+
int port) throws VOMSError {
277394

278395
return generateVOMSAttributeCertificate(defaultGenerationProperties, fqans, gas, targets,
279396
holderCert, serialNumber, notBefore, notAfter, voName, host, port);
280397
}
281398

399+
/**
400+
* Generates a VOMS attribute certificate with the specified properties.
401+
*
402+
* @param generationProperties the properties influencing AC generation
403+
* @param fqans the list of Fully Qualified Attribute Names (FQANs)
404+
* @param gas the list of generic attributes
405+
* @param targets the list of target restrictions
406+
* @param holderCert the X.509 certificate of the holder
407+
* @param serialNumber the serial number of the AC
408+
* @param notBefore the start of the AC validity period
409+
* @param notAfter the end of the AC validity period
410+
* @param voName the VO name
411+
* @param host the VOMS server hostname
412+
* @param port the VOMS server port
413+
* @return the generated X.509 attribute certificate
414+
* @throws VOMSError if certificate generation fails
415+
*/
282416
public X509AttributeCertificateHolder generateVOMSAttributeCertificate(
283417
EnumSet<ACGenerationProperties> generationProperties, List<String> fqans,
284418
List<VOMSGenericAttribute> gas, List<String> targets, X509Certificate holderCert,
285419
BigInteger serialNumber, Date notBefore, Date notAfter, String voName, String host,
286-
int port) {
420+
int port) throws VOMSError {
287421

288422
AttributeCertificateHolder holder = null;
289423
AttributeCertificateIssuer issuer = null;
@@ -345,6 +479,12 @@ public X509AttributeCertificateHolder generateVOMSAttributeCertificate(
345479

346480
}
347481

482+
/**
483+
* Generates a VOMS certificate extension.
484+
*
485+
* @param acs the list of X.509 attribute certificates
486+
* @return the generated certificate extension
487+
*/
348488
public CertificateExtension generateVOMSExtension(List<X509AttributeCertificateHolder> acs) {
349489

350490
ASN1EncodableVector vomsACs = new ASN1EncodableVector();

0 commit comments

Comments
 (0)