ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/realm/TestSecretKeyCredentialHandler.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/realm/TestSecretKeyCredentialHandler.java
Status
scanned
Type
file
Name
TestSecretKeyCredentialHandler.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3661 (3.6 KB)
MD5
345c23646845ddb8a792cf310d73db27
SHA1
ed4cc29ab1cff9b6e7cb4616f404f8ecf2d553fe
SHA256
6f4fe4caf5c27989112c6ead31de5c4b94cf6368607a0fc452181826910a48fc
SHA512

      
    
SHA1_git
bda5e095c2702ab506a9a6f5ad1c49be8fd5d0a4
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestSecretKeyCredentialHandler.java | 3.6 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.realm; import java.security.NoSuchAlgorithmException; import org.junit.Assert; import org.junit.Test; public class TestSecretKeyCredentialHandler { private static final String[] ALGORITHMS = { "PBKDF2WithHmacSHA1", "PBEWithMD5AndDES" }; private static final String[] PASSWORDS = { "password", "$!&#%!%@$#@*^$%&%%#!!*%$%&#@!^" }; private static final int[] KEYLENGTHS = { 8, 111, 256 }; private static final int[] SALTLENGTHS = { 1, 7, 12, 20 }; private static final int[] ITERATIONS = { 1, 2111, 10000 }; @Test public void testGeneral() throws Exception { for (String digest : ALGORITHMS) { for (String password : PASSWORDS) { for (int saltLength : SALTLENGTHS) { for (int iterations : ITERATIONS) { for (int keyLength : KEYLENGTHS) { doTest(password, digest, saltLength, iterations, keyLength, true); } } } } } } @Test public void testZeroSalt() throws NoSuchAlgorithmException { doTest(PASSWORDS[0], ALGORITHMS[0], 0, ITERATIONS[0], KEYLENGTHS[0], false); } @Test public void testZeroIterations() throws NoSuchAlgorithmException { doTest(PASSWORDS[0], ALGORITHMS[0], SALTLENGTHS[0], 0, KEYLENGTHS[0], false); } @Test public void testZeroKeyLength() throws NoSuchAlgorithmException { doTest(PASSWORDS[0], ALGORITHMS[0], SALTLENGTHS[0], ITERATIONS[0], 0, false); } private void doTest(String password, String digest, int saltLength, int iterations, int keyLength, boolean expectMatch) throws NoSuchAlgorithmException { SecretKeyCredentialHandler pbech = new SecretKeyCredentialHandler(); SecretKeyCredentialHandler verifier = new SecretKeyCredentialHandler(); pbech.setAlgorithm(digest); pbech.setIterations(iterations); pbech.setSaltLength(saltLength); pbech.setKeyLength(keyLength); verifier.setAlgorithm(digest); String storedCredential = pbech.mutate(password); if (expectMatch) { Assert.assertTrue( "[" + digest + "] [" + saltLength + "] [" + iterations + "] [" + keyLength + "] [" + password + "] [" + storedCredential + "]", verifier.matches(password, storedCredential)); } else { Assert.assertFalse( "[" + digest + "] [" + saltLength + "] [" + iterations + "] [" + keyLength + "] [" + password + "] [" + storedCredential + "]", verifier.matches(password, storedCredential)); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
35.84
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9