clean up module info
This commit is contained in:
parent
cdc4639347
commit
3049d51e96
7 changed files with 46 additions and 50 deletions
|
@ -22,10 +22,11 @@ jar {
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.compilerArgs.add('-Xlint:all,-exports')
|
options.compilerArgs.add('-Xlint:all')
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
}
|
}
|
||||||
|
|
||||||
javadoc {
|
tasks.withType(Javadoc) {
|
||||||
options.addStringOption('Xdoclint:none', '-quiet')
|
options.addStringOption('Xdoclint:none', '-quiet')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import org.xbib.net.security.CertificateProvider;
|
||||||
import org.xbib.net.bouncycastle.BouncyCastleCertificateProvider;
|
import org.xbib.net.bouncycastle.BouncyCastleCertificateProvider;
|
||||||
|
|
||||||
module org.xbib.net.bouncycastle {
|
module org.xbib.net.bouncycastle {
|
||||||
requires org.xbib.net.security;
|
requires transitive org.xbib.net.security;
|
||||||
requires org.bouncycastle.pkix;
|
requires org.bouncycastle.pkix;
|
||||||
requires org.bouncycastle.provider;
|
requires org.bouncycastle.provider;
|
||||||
exports org.xbib.net.bouncycastle;
|
exports org.xbib.net.bouncycastle;
|
||||||
|
|
|
@ -5,7 +5,6 @@ import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||||
import org.bouncycastle.openssl.PEMKeyPair;
|
import org.bouncycastle.openssl.PEMKeyPair;
|
||||||
import org.bouncycastle.openssl.PEMParser;
|
import org.bouncycastle.openssl.PEMParser;
|
||||||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
|
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
|
||||||
import org.bouncycastle.operator.OperatorCreationException;
|
|
||||||
import org.xbib.net.security.CertificateProvider;
|
import org.xbib.net.security.CertificateProvider;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -13,8 +12,6 @@ import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.NoSuchProviderException;
|
|
||||||
import java.security.PrivateKey;
|
import java.security.PrivateKey;
|
||||||
import java.security.Provider;
|
import java.security.Provider;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
@ -55,12 +52,8 @@ public class BouncyCastleCertificateProvider implements CertificateProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map.Entry<PrivateKey, Collection<? extends X509Certificate>> provideSelfSigned(String fullQualifiedDomainName) throws CertificateException, IOException {
|
public Map.Entry<PrivateKey, Collection<? extends X509Certificate>> provideSelfSigned(String fullQualifiedDomainName) throws CertificateException, IOException {
|
||||||
try {
|
SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate();
|
||||||
SelfSignedCertificate selfSignedCertificate = new SelfSignedCertificate();
|
selfSignedCertificate.generate(fullQualifiedDomainName, secureRandom, 2048);
|
||||||
selfSignedCertificate.generate(fullQualifiedDomainName, secureRandom, 2048);
|
return Map.entry(selfSignedCertificate.getPrivateKey(), List.of(selfSignedCertificate.getCertificate()));
|
||||||
return Map.entry(selfSignedCertificate.getPrivateKey(), List.of(selfSignedCertificate.getCertificate()));
|
|
||||||
} catch (NoSuchProviderException | NoSuchAlgorithmException | OperatorCreationException e) {
|
|
||||||
throw new IOException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,44 +70,45 @@ public final class SelfSignedCertificate {
|
||||||
* @param fqdn a fully qualified domain name
|
* @param fqdn a fully qualified domain name
|
||||||
* @param random the {@link SecureRandom} to use
|
* @param random the {@link SecureRandom} to use
|
||||||
* @param bits the number of bits of the generated private key
|
* @param bits the number of bits of the generated private key
|
||||||
* @throws NoSuchAlgorithmException if algorithm does not exist
|
|
||||||
* @throws NoSuchProviderException if provider does not exist
|
|
||||||
* @throws OperatorCreationException if provider does not exist
|
|
||||||
* @throws IOException if generation fails
|
* @throws IOException if generation fails
|
||||||
*/
|
*/
|
||||||
public void generate(String fqdn, SecureRandom random, int bits)
|
public void generate(String fqdn, SecureRandom random, int bits)
|
||||||
throws IOException, NoSuchProviderException, NoSuchAlgorithmException, OperatorCreationException {
|
throws IOException {
|
||||||
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC");
|
try {
|
||||||
keyGen.initialize(bits, random);
|
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA", "BC");
|
||||||
KeyPair keypair = keyGen.generateKeyPair();
|
keyGen.initialize(bits, random);
|
||||||
this.key = keypair.getPrivate();
|
KeyPair keypair = keyGen.generateKeyPair();
|
||||||
X500Name name = new X500Name("CN=" + fqdn);
|
this.key = keypair.getPrivate();
|
||||||
SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(keypair.getPublic().getEncoded());
|
X500Name name = new X500Name("CN=" + fqdn);
|
||||||
X509v3CertificateBuilder certificateBuilder =
|
SubjectPublicKeyInfo subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(keypair.getPublic().getEncoded());
|
||||||
new X509v3CertificateBuilder(name, BigInteger.valueOf(System.currentTimeMillis()),
|
X509v3CertificateBuilder certificateBuilder =
|
||||||
DEFAULT_NOT_BEFORE, DEFAULT_NOT_AFTER, name, subjectPublicKeyInfo);
|
new X509v3CertificateBuilder(name, BigInteger.valueOf(System.currentTimeMillis()),
|
||||||
AlgorithmIdentifier sigAlgId =
|
DEFAULT_NOT_BEFORE, DEFAULT_NOT_AFTER, name, subjectPublicKeyInfo);
|
||||||
new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256WithRSAEncryption");
|
AlgorithmIdentifier sigAlgId =
|
||||||
AlgorithmIdentifier digestAlgId =
|
new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256WithRSAEncryption");
|
||||||
new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
|
AlgorithmIdentifier digestAlgId =
|
||||||
AsymmetricKeyParameter caPrivateKeyParameters = PrivateKeyFactory.createKey(key.getEncoded());
|
new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
|
||||||
ContentSigner contentSigner = new BcRSAContentSignerBuilder(sigAlgId, digestAlgId)
|
AsymmetricKeyParameter caPrivateKeyParameters = PrivateKeyFactory.createKey(key.getEncoded());
|
||||||
.build(caPrivateKeyParameters);
|
ContentSigner contentSigner = new BcRSAContentSignerBuilder(sigAlgId, digestAlgId)
|
||||||
this.cert = certificateBuilder.build(contentSigner);
|
.build(caPrivateKeyParameters);
|
||||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
this.cert = certificateBuilder.build(contentSigner);
|
||||||
outputStream.write(BEGIN_KEY.getBytes(StandardCharsets.US_ASCII));
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
outputStream.write('\n');
|
outputStream.write(BEGIN_KEY.getBytes(StandardCharsets.US_ASCII));
|
||||||
writeEncoded(key.getEncoded(), outputStream);
|
outputStream.write('\n');
|
||||||
outputStream.write(END_KEY.getBytes(StandardCharsets.US_ASCII));
|
writeEncoded(key.getEncoded(), outputStream);
|
||||||
outputStream.write('\n');
|
outputStream.write(END_KEY.getBytes(StandardCharsets.US_ASCII));
|
||||||
this.keyBytes = outputStream.toByteArray();
|
outputStream.write('\n');
|
||||||
outputStream = new ByteArrayOutputStream();
|
this.keyBytes = outputStream.toByteArray();
|
||||||
outputStream.write(BEGIN_CERT.getBytes(StandardCharsets.US_ASCII));
|
outputStream = new ByteArrayOutputStream();
|
||||||
outputStream.write('\n');
|
outputStream.write(BEGIN_CERT.getBytes(StandardCharsets.US_ASCII));
|
||||||
writeEncoded(cert.getEncoded(), outputStream);
|
outputStream.write('\n');
|
||||||
outputStream.write(END_CERT.getBytes(StandardCharsets.US_ASCII));
|
writeEncoded(cert.getEncoded(), outputStream);
|
||||||
outputStream.write('\n');
|
outputStream.write(END_CERT.getBytes(StandardCharsets.US_ASCII));
|
||||||
this.certBytes = outputStream.toByteArray();
|
outputStream.write('\n');
|
||||||
|
this.certBytes = outputStream.toByteArray();
|
||||||
|
} catch (NoSuchProviderException | NoSuchAlgorithmException | OperatorCreationException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,5 +11,6 @@ module org.xbib.net.security {
|
||||||
exports org.xbib.net.security.eddsa.spec;
|
exports org.xbib.net.security.eddsa.spec;
|
||||||
exports org.xbib.net.security.signatures;
|
exports org.xbib.net.security.signatures;
|
||||||
exports org.xbib.net.security.ssl;
|
exports org.xbib.net.security.ssl;
|
||||||
|
exports org.xbib.net.security.ssl.trustmanager;
|
||||||
exports org.xbib.net.security.util;
|
exports org.xbib.net.security.util;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module org.xbib.net.socket {
|
module org.xbib.net.socket {
|
||||||
requires java.logging;
|
requires java.logging;
|
||||||
requires com.sun.jna;
|
requires transitive com.sun.jna;
|
||||||
exports org.xbib.net.socket;
|
exports org.xbib.net.socket;
|
||||||
exports org.xbib.net.socket.v4;
|
exports org.xbib.net.socket.v4;
|
||||||
exports org.xbib.net.socket.v4.bsd;
|
exports org.xbib.net.socket.v4.bsd;
|
||||||
|
|
|
@ -15,7 +15,7 @@ module org.xbib.net {
|
||||||
exports org.xbib.net.util;
|
exports org.xbib.net.util;
|
||||||
requires transitive org.xbib.datastructures.common;
|
requires transitive org.xbib.datastructures.common;
|
||||||
requires java.management;
|
requires java.management;
|
||||||
requires java.logging;
|
requires transitive java.logging;
|
||||||
uses DataBufferFactory;
|
uses DataBufferFactory;
|
||||||
provides DataBufferFactory with DefaultDataBufferFactory;
|
provides DataBufferFactory with DefaultDataBufferFactory;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue