### Manage Credentials and Realms with Elytron Tool Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Provides command-line examples for managing credential stores, masking passwords, and converting legacy vaults. Ensure the elytron-tool.sh script is in your path. ```bash # Elytron Tool is typically invoked via a script # Available commands: # - credential-store: Manage credential stores # - mask: Mask/encrypt clear text passwords # - vault: Convert legacy PicketBox vaults # - filesystem-realm: Create filesystem realms from properties files # - filesystem-realm-encrypt: Encrypt filesystem realm identities # - filesystem-realm-integrity: Add/verify integrity to realm files # Create a new credential store elytron-tool.sh credential-store \ --create \ --location /path/to/credential-store.cs \ --password "storePassword" # Add a credential to the store elytron-tool.sh credential-store \ --location /path/to/credential-store.cs \ --password "storePassword" \ --add dbpassword \ --secret "myDatabasePassword123" # List aliases in credential store elytron-tool.sh credential-store \ --location /path/to/credential-store.cs \ --password "storePassword" \ --aliases # Retrieve a credential elytron-tool.sh credential-store \ --location /path/to/credential-store.cs \ --password "storePassword" \ --alias dbpassword # Mask a password (for use in configuration files) elytron-tool.sh mask \ --salt 12345678 \ --iteration 230 \ --secret "mySecretPassword" # Output: MASK-;12345678;230 # Convert legacy PicketBox vault to credential store elytron-tool.sh vault \ --keystore /path/to/vault.keystore \ --keystore-password "vaultPassword" \ --enc-dir /path/to/vault/enc \ --salt 12345678 \ --iteration 50 \ --location /path/to/new-credential-store.cs \ --summary # Create filesystem realm from properties files elytron-tool.sh filesystem-realm \ --users-file /path/to/users.properties \ --roles-file /path/to/roles.properties \ --output-location /path/to/filesystem-realm \ --filesystem-realm-name myRealm ``` -------------------------------- ### Interactive release prompts Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/Releasing.md Examples of prompts encountered during the release preparation process. ```text What is the release version for "WildFly Elytron Parent"? (wildfly-elytron-parent) 2.8.1.CR1: 2.8.1.Final ``` ```text What is the SCM release tag or label for "WildFly Elytron Parent"? (wildfly-elytron-parent) 2.8.1.Final: ``` ```text What is the new development version for "WildFly Elytron Parent"? (wildfly-elytron-parent) 2.8.2.Final-SNAPSHOT: 2.8.2.CR1-SNAPSHOT ``` -------------------------------- ### Generate Key Pair Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tests/base/src/test/resources/ica/Readme.txt Generates a new Java KeyStore with a PrivateKeyEntry. Use this to start creating a new keystore. ```bash keytool -genkeypair -keystore jks/rove.keystore -alias rove -keyalg RSA -validity 3650 ``` -------------------------------- ### Generate JCEKS Keystore with keytool Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/src/test/resources/vault-v1-more/readme.txt Use the keytool command to generate a JCEKS keystore for storing secrets. Ensure you have Java Development Kit (JDK) installed. ```bash keytool -genseckey -alias test -storetype jceks -keystore vault-v1/vault-jceks.keystore -keyalg AES -keysize 128 -storepass secretsecret -keypass secretsecret ``` -------------------------------- ### Create and Manage FileSystemSecurityRealm Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Demonstrates how to create a FileSystemSecurityRealm, add new identities with passwords and attributes, and authenticate existing identities. Ensure the root directory exists and has appropriate permissions. ```java import org.wildfly.security.auth.realm.FileSystemSecurityRealm; import org.wildfly.security.auth.server.ModifiableRealmIdentity; import org.wildfly.security.auth.server.RealmIdentity; import org.wildfly.security.authz.MapAttributes; import org.wildfly.security.credential.PasswordCredential; import org.wildfly.security.password.interfaces.BCryptPassword; import java.nio.file.Paths; import java.util.Arrays; // Create a filesystem realm FileSystemSecurityRealm realm = FileSystemSecurityRealm.builder() .setRoot(Paths.get("/var/elytron/identities")) .setLevels(2) // Directory depth for identity files .setEncoded(true) // Base32 encode identity names .build(); // Create a new identity ModifiableRealmIdentity newIdentity = realm.getRealmIdentityForUpdate( new NamePrincipal("john.doe")); if (!newIdentity.exists()) { newIdentity.create(); // Set password credential PasswordFactory factory = PasswordFactory.getInstance(BCryptPassword.ALGORITHM_BCRYPT); BCryptPassword password = (BCryptPassword) factory.generatePassword( new ClearPasswordSpec("userPassword123".toCharArray())); newIdentity.setCredentials(Collections.singleton(new PasswordCredential(password))); // Set attributes MapAttributes attributes = new MapAttributes(); attributes.addAll("roles", Arrays.asList("user", "developer")); attributes.addFirst("email", "john.doe@example.com"); attributes.addFirst("department", "Engineering"); newIdentity.setAttributes(attributes); } newIdentity.dispose(); // Authenticate an identity RealmIdentity identity = realm.getRealmIdentity(new NamePrincipal("john.doe")); if (identity.exists()) { // Get credentials for verification PasswordCredential credential = identity.getCredential(PasswordCredential.class); if (credential != null) { PasswordFactory factory = PasswordFactory.getInstance(BCryptPassword.ALGORITHM_BCRYPT); boolean verified = factory.verify(credential.getPassword(), "userPassword123".toCharArray()); System.out.println("Password verified: " + verified); } // Get attributes Attributes attrs = identity.getAttributes(); System.out.println("Roles: " + attrs.get("roles")); } identity.dispose(); ``` -------------------------------- ### Initialize and Use CredentialStore Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Demonstrates initializing a KeyStore-based CredentialStore, storing password and secret key credentials, flushing changes, and retrieving credentials. Requires master password for protection. ```java import org.wildfly.security.credential.store.CredentialStore; import org.wildfly.security.credential.PasswordCredential; import org.wildfly.security.credential.SecretKeyCredential; import org.wildfly.security.password.Password; import org.wildfly.security.password.PasswordFactory; import org.wildfly.security.password.interfaces.ClearPassword; import org.wildfly.security.password.spec.ClearPasswordSpec; import org.wildfly.security.auth.server.IdentityCredentials; import java.util.HashMap; import java.util.Map; // Create protection parameter from a master password PasswordFactory passwordFactory = PasswordFactory.getInstance(ClearPassword.ALGORITHM_CLEAR); Password masterPassword = passwordFactory.generatePassword( new ClearPasswordSpec("masterStorePassword".toCharArray())); CredentialSource credentialSource = IdentityCredentials.NONE.withCredential( new PasswordCredential(masterPassword)); CredentialStore.CredentialSourceProtectionParameter protection = new CredentialStore.CredentialSourceProtectionParameter(credentialSource); // Initialize a KeyStore-based credential store CredentialStore credentialStore = CredentialStore.getInstance("KeyStoreCredentialStore"); Map attributes = new HashMap<>(); attributes.put("location", "/path/to/credential-store.jceks"); attributes.put("create", "true"); attributes.put("keyStoreType", "JCEKS"); credentialStore.initialize(attributes, protection); // Store a password credential Password secretPassword = passwordFactory.generatePassword( new ClearPasswordSpec("databasePassword123".toCharArray())); PasswordCredential passwordCredential = new PasswordCredential(secretPassword); credentialStore.store("db-password", passwordCredential); // Store a secret key credential SecretKeyCredential secretKeyCredential = new SecretKeyCredential( SecretKeyUtil.generateSecretKey(256)); credentialStore.store("encryption-key", secretKeyCredential); // Flush changes to persistent storage credentialStore.flush(); // Retrieve credentials PasswordCredential retrieved = credentialStore.retrieve("db-password", PasswordCredential.class); ClearPasswordSpec spec = passwordFactory.getKeySpec( retrieved.getPassword(), ClearPasswordSpec.class); char[] retrievedPassword = spec.getEncodedPassword(); // List all aliases Set aliases = credentialStore.getAliases(); for (String alias : aliases) { System.out.println("Stored credential: " + alias); } // Check if credential exists boolean exists = credentialStore.exists("db-password", PasswordCredential.class); ``` -------------------------------- ### Configure and Use SecurityDomain Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Demonstrates building a SecurityDomain with a simple realm, performing authentication, and executing code with an authenticated identity. Requires appropriate imports from the org.wildfly.security packages. ```java import org.wildfly.security.auth.server.SecurityDomain; import org.wildfly.security.auth.server.SecurityIdentity; import org.wildfly.security.auth.realm.SimpleMapBackedSecurityRealm; import org.wildfly.security.authz.RoleMapper; import org.wildfly.security.authz.Roles; import org.wildfly.security.evidence.PasswordGuessEvidence; // Build a security domain with a simple realm SimpleMapBackedSecurityRealm simpleRealm = new SimpleMapBackedSecurityRealm(); simpleRealm.setIdentityMap(Map.of( "admin", new SimpleRealmEntry( Collections.singletonList(new PasswordCredential( ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR, "adminpass".toCharArray()) )), new MapAttributes(Map.of("roles", Collections.singletonList("Administrator"))) ) )); SecurityDomain securityDomain = SecurityDomain.builder() .addRealm("default", simpleRealm) .setRoleDecoder(attributes -> Roles.fromSet( new HashSet<>(attributes.get("roles")))) .build() .setDefaultRealmName("default") .setPermissionMapper((principal, roles) -> LoginPermission.getInstance()) .build(); // Authenticate using evidence try { SecurityIdentity identity = securityDomain.authenticate("admin", new PasswordGuessEvidence("adminpass".toCharArray())); // Run code as the authenticated identity identity.runAs(() -> { // Code runs with the authenticated identity's permissions performAuthorizedOperation(); }); // Check roles if (identity.getRoles().contains("Administrator")) { System.out.println("User has admin privileges"); } } catch (SecurityException e) { System.err.println("Authentication failed: " + e.getMessage()); } // Create server authentication context for mechanism-based auth ServerAuthenticationContext authContext = securityDomain.createNewAuthenticationContext(); authContext.setAuthenticationName("admin"); if (authContext.verifyEvidence(new PasswordGuessEvidence("adminpass".toCharArray()))) { if (authContext.authorize()) { SecurityIdentity authorizedIdentity = authContext.getAuthorizedIdentity(); } } ``` -------------------------------- ### Build the project Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/CONTRIBUTING.md Commands for building the project with Maven, including options for skipping tests, running specific tests, and generating coverage reports. ```bash mvn clean install ``` ```bash mvn clean install -DskipTests=true ``` ```bash mvn clean install -Dtest=TestClassName ``` ```bash mvn -Ptest-coverage clean org.openclover:clover-maven-plugin:setup install org.openclover:clover-maven-plugin:aggregate org.openclover:clover-maven-plugin:clover ``` -------------------------------- ### Password Hashing and Verification with BCrypt Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Demonstrates hashing a password with BCrypt using default settings, custom salt and iterations, and then verifying it. Also shows conversion to and from modular crypt format for storage. ```java import org.wildfly.security.password.Password; import org.wildfly.security.password.PasswordFactory; import org.wildfly.security.password.interfaces.BCryptPassword; import org.wildfly.security.password.interfaces.ScramDigestPassword; import org.wildfly.security.password.interfaces.DigestPassword; import org.wildfly.security.password.spec.ClearPasswordSpec; import org.wildfly.security.password.spec.EncryptablePasswordSpec; import org.wildfly.security.password.spec.IteratedSaltedPasswordAlgorithmSpec; import org.wildfly.security.password.util.ModularCrypt; import org.wildfly.security.WildFlyElytronProvider; import java.security.Security; // Register the Elytron provider Security.addProvider(WildFlyElytronProvider.getInstance()); // BCrypt password hashing PasswordFactory bcryptFactory = PasswordFactory.getInstance(BCryptPassword.ALGORITHM_BCRYPT); // Hash a password with BCrypt (auto-generated salt, default iterations) BCryptPassword bcryptPassword = (BCryptPassword) bcryptFactory.generatePassword( new ClearPasswordSpec("mySecurePassword".toCharArray())); // Hash with specific salt and iteration count byte[] salt = new byte[BCryptPassword.BCRYPT_SALT_SIZE]; SecureRandom.getInstanceStrong().nextBytes(salt); BCryptPassword customBcrypt = (BCryptPassword) bcryptFactory.generatePassword( new EncryptablePasswordSpec("mySecurePassword".toCharArray(), new IteratedSaltedPasswordAlgorithmSpec(12, salt))); // Verify a password boolean isValid = bcryptFactory.verify(bcryptPassword, "mySecurePassword".toCharArray()); boolean isInvalid = bcryptFactory.verify(bcryptPassword, "wrongPassword".toCharArray()); // Convert to/from modular crypt format (for storage) String cryptString = ModularCrypt.encodeAsString(bcryptPassword); // Example output: $2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dq BCryptPassword decoded = (BCryptPassword) bcryptFactory.translate( ModularCrypt.decode(cryptString)); // SCRAM-SHA-256 password (for SASL authentication) PasswordFactory scramFactory = PasswordFactory.getInstance( ScramDigestPassword.ALGORITHM_SCRAM_SHA_256); ScramDigestPassword scramPassword = (ScramDigestPassword) scramFactory.generatePassword( new EncryptablePasswordSpec("password".toCharArray(), new IteratedSaltedPasswordAlgorithmSpec(4096, salt))); // Digest password (for HTTP Digest authentication) PasswordFactory digestFactory = PasswordFactory.getInstance( DigestPassword.ALGORITHM_DIGEST_SHA_256); DigestPassword digestPassword = (DigestPassword) digestFactory.generatePassword( new DigestPasswordSpec("username", "realm", "password".toCharArray())); ``` -------------------------------- ### Configure SASL Client with Elytron Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Demonstrates how to select SASL mechanisms, filter factories, and perform the authentication handshake. Requires appropriate security providers and a callback handler. ```java import org.wildfly.security.sasl.util.SaslMechanismInformation; import org.wildfly.security.sasl.util.FilterMechanismSaslClientFactory; import org.wildfly.security.sasl.util.SecurityProviderSaslClientFactory; import org.wildfly.security.sasl.SaslMechanismSelector; import javax.security.sasl.SaslClient; import javax.security.sasl.SaslClientFactory; import javax.security.sasl.Sasl; import java.util.HashMap; import java.util.Map; // Available SASL mechanism names String scram256 = SaslMechanismInformation.Names.SCRAM_SHA_256; // "SCRAM-SHA-256" String scram256Plus = SaslMechanismInformation.Names.SCRAM_SHA_256_PLUS; // "SCRAM-SHA-256-PLUS" String digestSha256 = SaslMechanismInformation.Names.DIGEST_SHA_256; // "DIGEST-SHA-256" String gssapi = SaslMechanismInformation.Names.GSSAPI; // "GSSAPI" String oauthBearer = SaslMechanismInformation.Names.OAUTHBEARER; // "OAUTHBEARER" String plain = SaslMechanismInformation.Names.PLAIN; // "PLAIN" // Create SASL client with mechanism selection SaslMechanismSelector selector = SaslMechanismSelector.fromString( "SCRAM-SHA-512 SCRAM-SHA-256 DIGEST-SHA-256 PLAIN"); // Get available mechanisms that match the selector String[] mechanisms = {"SCRAM-SHA-256", "DIGEST-MD5", "PLAIN"}; String selectedMechanism = selector.select(mechanisms); // Create filtered SASL client factory SaslClientFactory baseFactory = new SecurityProviderSaslClientFactory(); SaslClientFactory filteredFactory = new FilterMechanismSaslClientFactory( baseFactory, true, "SCRAM-SHA-256", "SCRAM-SHA-512"); // Create SASL client Map props = new HashMap<>(); props.put(Sasl.QOP, "auth-conf"); // Request confidentiality props.put(Sasl.SERVER_AUTH, "true"); // Request mutual authentication SaslClient client = filteredFactory.createSaslClient( new String[]{"SCRAM-SHA-256"}, "authorizationId", // Authorization ID (can be null) "protocol", // Protocol (e.g., "amqp", "xmpp") "server.example.com", // Server name props, callbackHandler); // Perform SASL authentication if (client.hasInitialResponse()) { byte[] response = client.evaluateChallenge(new byte[0]); // Send response to server... } while (!client.isComplete()) { byte[] challenge = receiveFromServer(); byte[] response = client.evaluateChallenge(challenge); if (response != null) { sendToServer(response); } } ``` -------------------------------- ### Configure and Evaluate HTTP Authentication Mechanisms Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Demonstrates creating callback handlers, initializing specific authentication factories, and evaluating requests using the HttpServerAuthenticationMechanism interface. ```java import org.wildfly.security.http.HttpAuthenticationException; import org.wildfly.security.http.HttpServerAuthenticationMechanism; import org.wildfly.security.http.HttpServerAuthenticationMechanismFactory; import org.wildfly.security.http.basic.BasicMechanismFactory; import org.wildfly.security.http.digest.DigestMechanismFactory; import org.wildfly.security.http.bearer.BearerMechanismFactory; import org.wildfly.security.auth.server.SecurityDomain; import org.wildfly.security.auth.server.http.HttpServerAuthenticationContext; import javax.security.auth.callback.CallbackHandler; import java.util.HashMap; import java.util.Map; // Create callback handler backed by security domain CallbackHandler callbackHandler = securityDomain.createNewAuthenticationContext() .createCallbackHandler(); // HTTP BASIC authentication mechanism HttpServerAuthenticationMechanismFactory basicFactory = new BasicMechanismFactory(); Map basicProps = new HashMap<>(); basicProps.put("realm", "Application Realm"); HttpServerAuthenticationMechanism basicMechanism = basicFactory.createAuthenticationMechanism( "BASIC", basicProps, callbackHandler); // HTTP DIGEST authentication mechanism HttpServerAuthenticationMechanismFactory digestFactory = new DigestMechanismFactory(); Map digestProps = new HashMap<>(); digestProps.put("realm", "Application Realm"); digestProps.put("algorithms", "SHA-256,SHA-512-256"); HttpServerAuthenticationMechanism digestMechanism = digestFactory.createAuthenticationMechanism( "DIGEST", digestProps, callbackHandler); // HTTP Bearer token authentication HttpServerAuthenticationMechanismFactory bearerFactory = new BearerMechanismFactory(); HttpServerAuthenticationMechanism bearerMechanism = bearerFactory.createAuthenticationMechanism( "BEARER_TOKEN", Collections.emptyMap(), callbackHandler); // Evaluate an HTTP request (in a servlet filter or similar) public void doFilter(HttpServerRequest request) throws HttpAuthenticationException { // The mechanism evaluates the request and calls appropriate callbacks basicMechanism.evaluateRequest(request); // After successful auth, get mechanism name String mechanismName = basicMechanism.getMechanismName(); // Get negotiated properties after authentication Object sslSession = basicMechanism.getNegotiatedProperty("SSL_SESSION"); } ``` -------------------------------- ### Build Project with Maven Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/README.md Executes a clean build and runs the embedded test suite. ```console $ mvn clean install ``` -------------------------------- ### Generate New Keystore with CA Signed Certificates Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tests/base/src/test/resources/ca/Readme.txt Use this sequence of commands to generate a new keystore and sign certificates with the CA. Ensure the environment is configured with 'openssl.env' and the CA password is 'Elytron'. ```bash keytool -genkeypair -keystore jks/scarab.keystore -alias scarab -keyalg RSA -validity 3650 ``` ```bash keytool -certreq -file scarab.csr -keystore jks/scarab.keystore -alias scarab ``` ```bash openssl ca -in scarab.csr ``` ```bash keytool -importcert -alias ca -file cacert.pkcs7 -keystore jks/scarab.keystore ``` ```bash keytool -importcert -trustcacerts -file certs/04.pem -alias scarab -keystore jks/scarab.keystore ``` -------------------------------- ### Create a Combined MatchRule Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Combine multiple matching criteria (protocol, host, port, path) into a single MatchRule for complex configuration selection. Ensure all components are correctly specified. ```java // Combined rule MatchRule combinedRule = MatchRule.ALL .matchProtocol("https") .matchHost("api.example.com") .matchPort(443) .matchPath("/secure/"); ``` -------------------------------- ### Execute Maven release commands Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/Releasing.md Commands to prepare and perform the release process. ```bash mvn release:prepare ``` ```bash mvn release:perform ``` -------------------------------- ### Run unit tests Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/CONTRIBUTING.md Execute existing unit tests using Maven. ```bash mvn clean test ``` -------------------------------- ### Configure Sonatype credentials in settings.xml Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/Releasing.md Add this server entry to your Maven settings.xml to authenticate with Sonatype for publishing. ```xml central XXX xxxxxxxxxxxxxxxxxxxxxx ``` -------------------------------- ### Create a MatchRule for Protocol Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Use matchProtocol to create a rule that matches a specific URI scheme, such as 'https' or 'http'. This helps in selecting configurations based on the communication protocol. ```java // Match protocol (URI scheme) MatchRule protocolRule = MatchRule.ALL.matchProtocol("https"); ``` -------------------------------- ### Clone the repository Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/CONTRIBUTING.md Use this command to clone your forked repository to your local machine. ```bash git clone [URL] ``` -------------------------------- ### Create a MatchRule for a Specific Host Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Configure a MatchRule to match a specific hostname. This is useful for directing traffic to a particular server. ```java // Match specific host MatchRule hostRule = MatchRule.ALL.matchHost("server.example.com"); ``` -------------------------------- ### Create a MatchRule for Host and Port Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Combine host and port matching in a MatchRule to target a specific service endpoint. Ensure the port number is correctly specified. ```java // Match host and port MatchRule hostPortRule = MatchRule.ALL .matchHost("server.example.com") .matchPort(8443); ``` -------------------------------- ### Clone the WildFly Elytron Tool repository Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/README.md Use this command to download the project source code from GitHub. ```bash git clone git@github.com:wildfly-security/wildfly-elytron-tool.git ``` -------------------------------- ### Build Server SSL Context with Custom Configuration Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Configures a server-side SSL context requiring client authentication, specifying key and trust stores, cipher suites, and protocols. Ensure the provided paths and passwords are correct. ```java import org.wildfly.security.ssl.SSLContextBuilder; import org.wildfly.security.ssl.CipherSuiteSelector; import org.wildfly.security.ssl.ProtocolSelector; import org.wildfly.security.auth.server.SecurityDomain; import javax.net.ssl.SSLContext; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.TrustManagerFactory; import java.security.KeyStore; // Load KeyStore for server certificate KeyStore keyStore = KeyStore.getInstance("PKCS12"); try (InputStream is = new FileInputStream("/path/to/server.p12")) { keyStore.load(is, "keystorePassword".toCharArray()); } KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); kmf.init(keyStore, "keyPassword".toCharArray()); // Load TrustStore for client certificate validation KeyStore trustStore = KeyStore.getInstance("PKCS12"); try (InputStream is = new FileInputStream("/path/to/truststore.p12")) { trustStore.load(is, "truststorePassword".toCharArray()); } TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509"); tmf.init(trustStore); // Build server SSL context SSLContext serverContext = new SSLContextBuilder() .setKeyManager(kmf.getKeyManagers()[0]) .setTrustManager(tmf.getTrustManagers()[0]) .setCipherSuiteSelector(CipherSuiteSelector.fromString( "TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256:!NULL:!EXPORT")) .setProtocolSelector(ProtocolSelector.fromString("TLSv1.3 TLSv1.2")) .setSessionTimeout(3600) .setSessionCacheSize(100) .setUseCipherSuitesOrder(true) .setNeedClientAuth(true) // Require client certificates .build() .create(); ``` -------------------------------- ### Build Client SSL Context Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Configures a client-side SSL context, specifying the trust store and desired protocols. This is used for establishing secure connections from a client. ```java SSLContext clientContext = new SSLContextBuilder() .setTrustManager(tmf.getTrustManagers()[0]) .setClientMode(true) .setProtocolSelector(ProtocolSelector.fromString("TLSv1.3 TLSv1.2")) .build() .create(); ``` -------------------------------- ### Create a MatchRule for All URIs Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Use MatchRule.ALL to create a rule that matches all URIs. This is often used as a base for more specific rules or as a fallback. ```java import org.wildfly.security.auth.client.MatchRule; import java.net.URI; // The root rule that matches everything MatchRule matchAll = MatchRule.ALL; ``` -------------------------------- ### Create a MatchRule for User Info Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Match a specific username present in the URI's user info component. This allows for user-specific configuration selection. ```java // Match user info from URI MatchRule userRule = MatchRule.ALL.matchUser("admin"); ``` -------------------------------- ### Import CA Certificate into Keystore Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tests/base/src/test/resources/ica/Readme.txt Imports the CA's root certificate into the target keystore. This establishes trust for certificates issued by this CA. ```bash keytool -importcert -alias ca -file ../ca/cacert.pem -keystore jks/rove.keystore ``` -------------------------------- ### Build SSL Context with SecurityDomain Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Creates an SSL context that integrates with a SecurityDomain for certificate-based authentication, allowing for optional client authentication. ```java SSLContext domainContext = new SSLContextBuilder() .setSecurityDomain(securityDomain) .setKeyManager(kmf.getKeyManagers()[0]) .setTrustManager(tmf.getTrustManagers()[0]) .setWantClientAuth(true) // Request but don't require client certs .setAuthenticationOptional(true) // Allow fallback if cert auth fails .build() .create(); ``` -------------------------------- ### Configure Client AuthenticationContext Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Defines authentication rules and SSL contexts for outbound connections using a fluent API. The context is applied to a block of code using the run method. ```java import org.wildfly.security.auth.client.AuthenticationContext; import org.wildfly.security.auth.client.AuthenticationConfiguration; import org.wildfly.security.auth.client.MatchRule; import org.wildfly.security.ssl.SSLContextBuilder; import javax.net.ssl.SSLContext; // Create authentication configurations for different services AuthenticationConfiguration dbConfig = AuthenticationConfiguration.empty() .useName("dbuser") .usePassword("dbpassword") .useProtocol("jdbc"); AuthenticationConfiguration jmsConfig = AuthenticationConfiguration.empty() .useName("jmsuser") .usePassword("jmspassword") .usePort(5672); // Build SSL context for secure connections SSLContext sslContext = new SSLContextBuilder() .setSessionTimeout(3600) .build() .create(); // Create authentication context with rules AuthenticationContext context = AuthenticationContext.empty() .with(MatchRule.ALL.matchHost("database.example.com"), dbConfig) .with(MatchRule.ALL.matchHost("messaging.example.com").matchPort(5672), jmsConfig) .withSsl(MatchRule.ALL.matchProtocol("https"), () -> sslContext); // Run code with the authentication context context.run(() -> { // All outbound connections made here will use the configured authentication // based on the matching rules return performSecureOperation(); }); // Capture current thread's authentication context AuthenticationContext currentContext = AuthenticationContext.captureCurrent(); ``` -------------------------------- ### Generate JCEKS Keystore on IBM JDK Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/src/test/resources/vault-v1-more/readme.txt Create a JCEKS keystore specifically for use with IBM JDK, addressing potential compatibility issues. This command is similar to the standard keystore generation but uses a different keystore file name. ```bash keytool -genseckey -alias test -storetype jceks -keystore vault-v1/vault-jceks-ibm.keystore -keyalg AES -keysize 128 -storepass secretsecret -keypass secretsecret ``` -------------------------------- ### Create a MatchRule for No User Info Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Create a rule that matches URIs where no user information is present. This is useful for configurations that apply when authentication credentials are not provided in the URI. ```java // Match when no user info is present MatchRule noUserRule = MatchRule.ALL.matchNoUser(); ``` -------------------------------- ### Generate RSA Key Pair with keytool Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/x500/cert/acme/src/test/resources/org/wildfly/security/x500/cert/acme/readme.txt Generates an RSA key pair with a specified alias, keystore, key algorithm, key size, validity period, key password, and store password. Use this for standard key generation. ```bash keytool -genkeypair -alias account1v2 -keystore account.keystore -dname CN=account1v2.key -keyalg RSA -keysize 2048 -validity 3650 -keypass elytron -storepass elytron ``` ```bash keytool -genkeypair -alias account2v2 -keystore account.keystore -dname CN=account2v2.key -keyalg RSA -keysize 2048 -validity 3650 -keypass elytron -storepass elytron ``` ```bash keytool -genkeypair -alias account3v2 -keystore account.keystore -dname CN=account3v2.key -keyalg RSA -keysize 2048 -validity 3650 -keypass elytron -storepass elytron ``` ```bash keytool -genkeypair -alias account5v2 -keystore account.keystore -dname CN=account5v2.key -keyalg RSA -keysize 2048 -validity 3650 -keypass elytron -storepass elytron ``` ```bash keytool -genkeypair -alias account6v2 -keystore account.keystore -dname CN=account6v2.key -keyalg RSA -keysize 2048 -validity 3650 -keypass elytron -storepass elytron ``` ```bash keytool -genkeypair -alias account7v2 -keystore account.keystore -dname CN=account7v2.key -keyalg RSA -keysize 2048 -validity 3650 -keypass elytron -storepass elytron ``` ```bash keytool -genkeypair -alias account8v2 -keystore account.keystore -dname CN=account8v2.key -keyalg RSA -keysize 2048 -validity 3650 -keypass elytron -storepass elytron ``` ```bash keytool -genkeypair -alias account9v2 -keystore account.keystore -dname CN=account9v2.key -keyalg RSA -keysize 2048 -validity 3650 -keypass elytron -storepass elytron ``` ```bash keytool -genkeypair -alias newKeyv2 -keystore account.keystore -dname CN=account8v2.key -keyalg RSA -keysize 2048 -validity 3650 -keypass elytron -storepass elytron ``` -------------------------------- ### Convert Public Key to PKCS8 Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/src/test/resources/ssh-keys/README.txt Converts an existing public key file into the PKCS8 format. ```bash $ ssh-keygen -f id_ecdsa_pkcs.pub -e -m pkcs8 ``` -------------------------------- ### Create Vault Content with vault.sh (Standard) Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/src/test/resources/vault-v1-more/readme.txt Encrypt sensitive data into vault files using the vault.sh script. This requires a pre-existing keystore and specific parameters for encryption. ```bash ./bin/vault.sh -e vault-v1/vault_data/ -k vault-v1/vault-jceks.keystore -v test -p secretsecret -i 34 -s 12345678 -b vb1 -a attr11 -x secret11 ``` ```bash ./bin/vault.sh -e vault-v1/vault_data/ -k vault-v1/vault-jceks.keystore -v test -p secretsecret -i 34 -s 12345678 -b vb1 -a attr12 -x secret12 ``` -------------------------------- ### Clone WildFly Elytron Repository Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/README.md Use this command to clone the source code from the official GitHub repository. ```console $ git clone git@github.com:wildfly-security/wildfly-elytron.git ``` -------------------------------- ### Import ICA Certificate into Keystore Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tests/base/src/test/resources/ica/Readme.txt Imports the Intermediate Certificate Authority's certificate into the keystore. This is a step in establishing a certificate chain. ```bash keytool -importcert -alias ica -file icacert.pem -keystore jks/rove.keystore ``` -------------------------------- ### Import Signed Certificate into Keystore Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tests/base/src/test/resources/ica/Readme.txt Imports the signed certificate (obtained after signing the CSR) into the keystore. This completes the process of adding a CA-signed certificate. ```bash keytool -importcert -trustcacerts -file certs/00.pem -alias rove -keystore jks/rove.keystore ``` -------------------------------- ### Configure AuthenticationContext with MatchRules Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Use MatchRules within an AuthenticationContext to associate specific authentication configurations with different rules. This allows for dynamic selection of configurations based on URI properties. ```java // Use with AuthenticationContext AuthenticationContext context = AuthenticationContext.empty() .with(MatchRule.ALL.matchHost("db.example.com").matchPort(5432), dbConfig) .with(MatchRule.ALL.matchHost("*.internal.example.com"), internalConfig) .with(MatchRule.ALL.matchProtocol("https"), secureConfig) .with(MatchRule.ALL, defaultConfig); // Fallback for unmatched URIs ``` -------------------------------- ### Verify release commit Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/Releasing.md Check the release commit using the generated tag. ```bash git show ${TAG} ``` -------------------------------- ### Generate Certificate Signing Request (CSR) Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tests/base/src/test/resources/ica/Readme.txt Creates a certificate signing request from an existing keystore. This CSR is then used to obtain a signed certificate. ```bash keytool -certreq -file rove.csr -keystore jks/rove.keystore -alias rove ``` -------------------------------- ### Configure upstream remote Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/CONTRIBUTING.md Add the upstream repository as a remote to pull future updates. ```bash git remote add upstream https://github.com/wildfly-security/wildfly-elytron ``` -------------------------------- ### Encrypt Vault Data (Standard) Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/src/test/resources/vault-v1/readme.txt Use the vault script to encrypt data. Specify the encryption directory, keystore, alias, password, iteration count, and salt. ```bash ./bin/vault.sh -e vault-v1/vault_data/ -k vault-v1/vault-jceks.keystore -v test -p secretsecret -i 34 -s 12345678 -b vb1 -a attr11 -x secret11 ``` ```bash ./bin/vault.sh -e vault-v1/vault_data/ -k vault-v1/vault-jceks.keystore -v test -p secretsecret -i 34 -s 12345678 -b vb1 -a attr12 -x secret12 ``` ```bash ./bin/vault.sh -e vault-v1/vault_data_ibm/ -k vault-v1/vault-jceks-ibm.keystore -v test -p secretsecret -i 34 -s 12345678 -b vb1 -a attr11 -x secret11 ``` ```bash ./bin/vault.sh -e vault-v1/vault_data_ibm/ -k vault-v1/vault-jceks-ibm.keystore -v test -p secretsecret -i 34 -s 12345678 -b vb1 -a attr12 -x secret12 ``` -------------------------------- ### Create a MatchRule for Network Range Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Define a MatchRule to match URIs originating from a specific network range using CIDR notation. This requires the CidrAddress class. ```java // Match network range (CIDR notation) MatchRule networkRule = MatchRule.ALL.matchNetwork( CidrAddress.create("192.168.1.0", 24)); ``` -------------------------------- ### Create Vault Content with vault.sh (IBM JDK) Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/src/test/resources/vault-v1-more/readme.txt Encrypt sensitive data into vault files using the vault.sh script when targeting an IBM JDK environment. This uses a keystore generated specifically for IBM JDK. ```bash ./bin/vault.sh -e vault-v1/vault_data_ibm/ -k vault-v1/vault-jceks-ibm.keystore -v test -p secretsecret -i 34 -s 12345678 -b vb1 -a attr11 -x secret11 ``` ```bash ./bin/vault.sh -e vault-v1/vault_data_ibm/ -k vault-v1/vault-jceks-ibm.keystore -v test -p secretsecret -i 34 -s 12345678 -b vb1 -a attr12 -x secret12 ``` -------------------------------- ### Push release to remote Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/Releasing.md Push the branch and tag to the upstream repository. ```bash git push upstream ${BRANCH} git push upstream ${TAG} ``` -------------------------------- ### Generate EC Key Pair with keytool Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/x500/cert/acme/src/test/resources/org/wildfly/security/x500/cert/acme/readme.txt Generates an Elliptic Curve (EC) key pair with a specified alias, keystore, key algorithm, key size, validity period, key password, and store password. Use this for EC cryptography. ```bash keytool -genkeypair -alias account4v2 -keystore account.keystore -dname CN=account4v2.key -keyalg EC -keysize 256 -validity 3650 -keypass elytron -storepass elytron ``` ```bash keytool -genkeypair -alias newECKeyv2 -keystore account.keystore -dname CN=account8v2.key -keyalg EC -keysize 256 -validity 3650 -keypass elytron -storepass elytron ``` -------------------------------- ### Create a MatchRule for URN Name Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Use matchUrnName to create a rule that matches Uniform Resource Names (URNs). This is specifically for non-hierarchical URIs. ```java // Match URN (for non-hierarchical URIs) MatchRule urnRule = MatchRule.ALL.matchUrnName("example:resource:123"); ``` -------------------------------- ### Define AuthenticationConfiguration Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Creates immutable authentication configurations for various mechanisms including SASL, Kerberos, certificates, and bearer tokens. ```java import org.wildfly.security.auth.client.AuthenticationConfiguration; import org.wildfly.security.auth.principal.NamePrincipal; import org.wildfly.security.credential.PasswordCredential; import org.wildfly.security.password.interfaces.ClearPassword; import org.wildfly.security.sasl.SaslMechanismSelector; // Basic configuration with username and password AuthenticationConfiguration basicConfig = AuthenticationConfiguration.empty() .useName("admin") .usePassword("secretpassword") .useRealm("ApplicationRealm"); // Configuration with SASL mechanism selection AuthenticationConfiguration saslConfig = AuthenticationConfiguration.empty() .useName("serviceuser") .usePassword("servicepass") .setSaslMechanismSelector(SaslMechanismSelector.fromString("SCRAM-SHA-256 DIGEST-SHA-256")) .useHost("remote-server.example.com") .usePort(8443) .useProtocol("remote"); // Configuration with Kerberos authentication AuthenticationConfiguration kerberosConfig = AuthenticationConfiguration.empty() .useGSSCredential(gssCredential) .useSaslMechanismSelector(SaslMechanismSelector.fromString("GSSAPI")); // Configuration with certificate-based authentication AuthenticationConfiguration certConfig = AuthenticationConfiguration.empty() .useCertificateCredential(privateKey, certificateChain) .useKeyManagerFactory(keyManagerFactory); // Configuration with bearer token AuthenticationConfiguration tokenConfig = AuthenticationConfiguration.empty() .useBearerTokenCredential(new BearerTokenCredential("eyJhbGciOiJSUzI1NiIs...")); ``` -------------------------------- ### Vault Configuration XML Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/src/test/resources/vault-v1/readme.txt Configure vault options within an XML structure. This defines the keystore location, password, alias, and encryption parameters. ```xml ``` ```xml ``` -------------------------------- ### Elytron Client Authentication XML Configuration Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt This XML configuration defines various aspects of client authentication, including credential stores, key stores, authentication configurations, authentication rules, and SSL contexts. It is used to set up secure communication and authentication mechanisms for Elytron clients. ```xml ``` -------------------------------- ### Create a MatchRule for Path Source: https://context7.com/wildfly-security/wildfly-elytron/llms.txt Define a MatchRule to match a specific path within a URI. This is useful for routing requests to different services based on their endpoint. ```java // Match path MatchRule pathRule = MatchRule.ALL.matchPath("/api/v1/"); ``` -------------------------------- ### Rollback release Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/Releasing.md Commands to reset local git state if a release fails. ```bash git reset --hard upstream/${BRANCH} git tag --delete ${TAG} ``` -------------------------------- ### Generate ECDSA Key in PKCS8 Format Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/src/test/resources/ssh-keys/README.txt Generates an ECDSA key pair specifically formatted for PKCS8 compatibility. ```bash $ ssh-keygen -t ecdsa -m pkcs8 ``` -------------------------------- ### Generate ECDSA SSH Key Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tool/src/test/resources/ssh-keys/README.txt Creates a standard ECDSA public/private key pair using the ssh-keygen utility. ```bash $ ssh-keygen -t ecdsa ``` -------------------------------- ### Revoke Certificate and Create CRL Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/tests/base/src/test/resources/ca/Readme.txt Commands to revoke a certificate and generate a Certificate Revocation List (CRL). The 'firefly' certificate is revoked, and a CRL file is created. ```bash openssl ca -revoke certs/01.pem ``` ```bash openssl ca -gencrl -out crl/firefly-revoked.pem ``` -------------------------------- ### Forward merge maintenance branches Source: https://github.com/wildfly-security/wildfly-elytron/blob/2.x/Releasing.md Commands to synchronize changes between maintenance branches. ```bash git checkout -b 2_2_x_sync -t upstream/2.2.x ``` ```bash git merge 64e0bd99c9edb8e4456905a8e104bf129bcaa38b -m "Sync from 1.15.x" ``` ```bash git merge -s ours 1.15.x -m "Sync version commits from 1.15.x" ```