SignatureKeyManager { public KeyPair getOrCreateKeyPair(String workspaceId) throws SignatureKeyManagerException { SignatureKeyPair keyPair; try { try { keyPair = signatureKeyDao.get(workspaceId); } catch (NotFoundException e) { keyPair = generateKeyPair(workspaceId); } } catch (NoSuchAlgorithmException | ServerException | ConflictException ex) { LOG.error( "Failed to load signature keys for ws {}. Cause: {}", workspaceId, ex.getMessage()); throw new SignatureKeyManagerException(ex.getMessage(), ex); } return toJavaKeyPair(keyPair); } @Inject  SignatureKeyManager(
      @Named("che.auth.signature_key_size") int keySize,
      @Named("che.auth.signature_key_algorithm") String algorithm,
      EventService eventService,
      SignatureKeyDao signatureKeyDao); KeyPair getOrCreateKeyPair(String workspaceId); static final String PKCS_8; static final String X_509; }
@Test(expectedExceptions = SignatureKeyManagerException.class) public void shouldThrowsExceptionWhenAlgorithmIsNotSupported() throws Exception { final SignatureKeyImpl publicKey = new SignatureKeyImpl(new byte[] {}, "ECDH", "PKCS#15"); final SignatureKeyImpl privateKey = new SignatureKeyImpl(new byte[] {}, "ECDH", "PKCS#3"); final SignatureKeyPairImpl kp = new SignatureKeyPairImpl("id_" + 1, publicKey, privateKey); doReturn(kp).when(signatureKeyDao).get(anyString()); signatureKeyManager.getOrCreateKeyPair("ws1"); verify(signatureKeyDao).get(anyString()); }
@Test public void shouldReturnSignatureKeys() throws Exception { String wsId = "WS_id_1"; final SignatureKeyPairImpl kp = newKeyPair(wsId); when(signatureKeyDao.get(anyString())).thenReturn(kp); final KeyPair cachedPair = signatureKeyManager.getOrCreateKeyPair(wsId); assertNotNull(cachedPair); assertKeys(cachedPair.getPublic(), kp.getPublicKey()); assertKeys(cachedPair.getPrivate(), kp.getPrivateKey()); }