Exemplo n.º 1
0
  @Test
  public void testHandleInternal() throws CertificateException {
    final CertificateFactory cf = CertificateFactory.getInstance("X.509");
    U2FReceiverInterface receiver = mock(U2FReceiverInterface.class);
    Module actor = mock(Module.class);
    String version = "U2F_V2";
    byte[] clientParam =
        BaseEncoding.base64Url().decode("MUmwdr0pxe9YsU-P78JNG7s0CNpL8Q41kM7vLWxh6_I=");
    byte[] appParam =
        BaseEncoding.base64Url().decode("shPs6qCuWEVuIMbYe7LP6YJTAsuNm52zDg8ivpfq3P8=");
    byte[] encodedRandom =
        BaseEncoding.base64()
            .decode(
                "2KmIHW8wLzt/eW0Awry1NvfYV9pJVYhERjKwCzkSPG7KYFZScRV8h1z02DELcVhkEDAYFemMKLe+lPQFF2iyqaEsbCBYqLVx82FU8uuktcE+ZFAXyMjprN1jOoARJNRHvd1+nBYkn/plZFUW1X236U1izs0c7xf/4VWPuwI/m5BSyBmY/YKaIQdpGwToCYdcD/5NjaI76mTlHDWNt4f9Ug==");
    byte[] encodedKey =
        BaseEncoding.base64()
            .decode(
                "MIIQ3gIBATEPMA0GCWCGSAFlAwQCAQUAMIILggYJKoZIhvcNAQcBoIILcwSCC28wggtrBgsqhkiG9w0BCRABF6CCC1owggtWAgEAMYIBZzCCAWMCAQAwSzBAMSIwIAYDVQQDExlJQUlLIFRlc3QgSW50ZXJtZWRpYXRlIENBMQ0wCwYDVQQKEwRJQUlLMQswCQYDVQQGEwJBVAIHARTz1EoFiDANBgkqhkiG9w0BAQEFAASCAQAJhWfH6gMHOJFUBKA5FZ9HaVFq4CRkriSH0VyQh2KBA2p/UyKOcMDfeQBcjPAWoipFGDptaR8trt+Lb3m/IVRGnZmfPXEQG6amq3LLV95Yf5BTm07wvo5WiTk2E37PcOpDVMuDfxHjrkg51HszvgKmdOcY4RZRqMvkvwFg60oF5tkE9g0Ye8jUU1Gw3I3xg7mJFJVMGmGgSPGD/HcJWD02BnDg7cLx51720WEXQJoXvCRKMoLhiZmQMBj0ZS0hv2vrgRKt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1KjnxyH1d9hAgMBAAGjSjBIMCUGA1UdEQQeMByBGnBldGVyLnRldWZsQGlhaWsudHVncmF6LmF0MB8GA1UdIwQYMBaAFGiiXhHa3i+Aa0REv436ZTaBJKdvMA0GCSqGSIb3DQEBBQUAA4GBADoJjvmqooO69eM9yGE1xUMsEJ2N8onq1BUHKPwfQd8Au4TcKSk6bGLcsSTrGuOSXaPmPmo0aQBjfkjeZRyC5x8ipQcySYVB8FdMgZwEEVlxlz9qqvndJnDOtid84ZgopV2AjcO0WG5nGOvXncADbACK/v8CMQujdX4thq+XETBpMYIB4TCCAd0CAQEwSzBAMSIwIAYDVQQDExlJQUlLIFRlc3QgSW50ZXJtZWRpYXRlIENBMQ0wCwYDVQQKEwRJQUlLMQswCQYDVQQGEwJBVAIHARTz1EoFiDANBglghkgBZQMEAgEFAKBpMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTE1MTIwMzEyMjMzOFowLwYJKoZIhvcNAQkEMSIEIP4e/ZL5mxGSoXVk2ctkTtAgdxyGKSIB5eNiscVgPNHiMA0GCSqGSIb3DQEBAQUABIIBAJxFPi7OZ4FUK673XueLow4TB/Ji+7wtq6lfcJFregY96adYxHOMWlpvyNLzyIWJxV1SczHVatti4BGMWiGM1OJU4IXRzuojGVRzmL9CcDsUU1amokYqS//98SnzDMW4obNLqq0xKtawrSo/Hl1/eVbBYilLmtPaMszQ+cl0xQ5ReTybeKC08O6pTfwLx47YiretEoVwgpagVC2tdGN/UqM/KX+saox5NJIzhx+8UP5BdG35mMCa71fs5dxKQKYTxaKHK3w+Sq7mwKaxopgioJ4x4w9fq8+qdEYQWUaBTJiIVfBbJXdVkPD4xOnUFIbfxHqXn9DQHhAqQb0Ex3zt4Fo=");
    X509Certificate encodedCert =
        (X509Certificate)
            cf.generateCertificate(
                new ByteArrayInputStream(
                    BaseEncoding.base64()
                        .decode(
                            "MIICqDCCAZACIHCy6N/T8VQ8XOlp3EBkT9D1uw3uXMpuaIuwyYVtYdPRMA0GCSqGSIb3DQEBCwUAMIHMMQswCQYDVQQGEwJBVDENMAsGA1UEBxMER3JhejEmMCQGA1UEChMdR3JheiBVbml2ZXJzaXR5IG9mIFRlY2hub2xvZ3kxSDBGBgNVBAsTP0luc3RpdHV0ZSBmb3IgQXBwbGllZCBJbmZvcm1hdGlvbiBQcm9jZXNzaW5nIGFuZCBDb21tdW5pY2F0aW9uczESMBAGA1UEBBMJVGV1ZmwgRW5jMQ4wDAYDVQQqEwVQZXRlcjEYMBYGA1UEAxMPUGV0ZXIgVGV1ZmwgRW5jMB4XDTEzMDkwOTEwMzcxMloXDTIzMDkwOTEwMzcxMlowEzERMA8GA1UEAxMIU2t5VHJ1c3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAR+XOmSfxB8SU3A4PUmFB89awcIGnXLxBpnqHxltHLQg6evGeVhSmLqUDXYXKljHRpkITruRMVxlPZGREoTKFK8MA0GCSqGSIb3DQEBCwUAA4IBAQDC/ICTEa4sNE9paFCU8FJJ2o1eZ6Zzarx5jWtk6rd1KtB/jzQVvR/V4wq+3ItbEufdKh3HhHA2K9uEZm+Mu7t8FUaXFKAyksU2/PzI3kFUVsSoE7XiSuhyivUbT9xdWNTc4ZLJecrq5weJwkhoqLpW1ec1jGaFEpGMPlVGMJC8ANRGkc3ddeckAck8cdItR8wQ5ltEpiTklyoleIeTzu2kThl7mKc8CkqIiXcudNnKqY1USJ+Ns5jjLDStyy7+mLw45Y5p8U71Wmx2DEIkH/ExDWedMXIXdKvHD8BgTsbKNf70zZspwqMnDqThgi3Oio4VRWvKuszhmP++UZHoQobo")));
    byte[] hashToBeSigned =
        BaseEncoding.base64()
            .decode(
                "ALIT7OqgrlhFbiDG2Huyz+mCUwLLjZudsw4PIr6X6tz/MUmwdr0pxe9YsU+P78JNG7s0CNpL8Q41kM7vLWxh6/LYqYgdbzAvO395bQDCvLU299hX2klViERGMrALORI8bspgVlJxFXyHXPTYMQtxWGQQMBgV6Ywot76U9AUXaLKpoSxsIFiotXHzYVTy66S1wT5kUBfIyOms3WM6gBEk1Ee93X6cFiSf+mVkVRbVfbfpTWLOzRzvF//hVY+7Aj+bkFLIGZj9gpohB2kbBOgJh1wP/k2NojvqZOUcNY23h/1SBH5c6ZJ/EHxJTcDg9SYUHz1rBwgadcvEGmeofGW0ctCDp68Z5WFKYupQNdhcqWMdGmQhOu5ExXGU9kZEShMoUrw=");
    byte[] signedHash =
        BaseEncoding.base64()
            .decode(
                "MEUCICF+1fY8V/y5/kUw35/mnlSbZzs236wH3wsZQSfSiKnvAiEAyF/md0WTjq53G+t1h8HPaJlYmhoSP8Wej8R6bTUoFxw=");
    byte[] registrationData =
        BaseEncoding.base64Url()
            .decode(
                "BQR-XOmSfxB8SU3A4PUmFB89awcIGnXLxBpnqHxltHLQg6evGeVhSmLqUDXYXKljHRpkITruRMVxlPZGREoTKFK8oNipiB1vMC87f3ltAMK8tTb32FfaSVWIREYysAs5EjxuymBWUnEVfIdc9NgxC3FYZBAwGBXpjCi3vpT0BRdosqmhLGwgWKi1cfNhVPLrpLXBPmRQF8jI6azdYzqAESTUR73dfpwWJJ_6ZWRVFtV9t-lNYs7NHO8X_-FVj7sCP5uQUsgZmP2CmiEHaRsE6AmHXA_-TY2iO-pk5Rw1jbeH_VIwggKoMIIBkAIgcLLo39PxVDxc6WncQGRP0PW7De5cym5oi7DJhW1h09EwDQYJKoZIhvcNAQELBQAwgcwxCzAJBgNVBAYTAkFUMQ0wCwYDVQQHEwRHcmF6MSYwJAYDVQQKEx1HcmF6IFVuaXZlcnNpdHkgb2YgVGVjaG5vbG9neTFIMEYGA1UECxM_SW5zdGl0dXRlIGZvciBBcHBsaWVkIEluZm9ybWF0aW9uIFByb2Nlc3NpbmcgYW5kIENvbW11bmljYXRpb25zMRIwEAYDVQQEEwlUZXVmbCBFbmMxDjAMBgNVBCoTBVBldGVyMRgwFgYDVQQDEw9QZXRlciBUZXVmbCBFbmMwHhcNMTMwOTA5MTAzNzEyWhcNMjMwOTA5MTAzNzEyWjATMREwDwYDVQQDEwhTa3lUcnVzdDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABH5c6ZJ_EHxJTcDg9SYUHz1rBwgadcvEGmeofGW0ctCDp68Z5WFKYupQNdhcqWMdGmQhOu5ExXGU9kZEShMoUrwwDQYJKoZIhvcNAQELBQADggEBAML8gJMRriw0T2loUJTwUknajV5npnNqvHmNa2Tqt3Uq0H-PNBW9H9XjCr7ci1sS590qHceEcDYr24Rmb4y7u3wVRpcUoDKSxTb8_MjeQVRWxKgTteJK6HKK9RtP3F1Y1Nzhksl5yurnB4nCSGioulbV5zWMZoUSkYw-VUYwkLwA1EaRzd115yQByTxx0i1HzBDmW0SmJOSXKiV4h5PO7aROGXuYpzwKSoiJdy502cqpjVRIn42zmOMsNK3LLv6YvDjljmnxTvVabHYMQiQf8TENZ50xchd0q8cPwGBOxso1_vTNmynCoycOpOGCLc6KjhVFa8q6zOGY_75RkehChugwRQIgIX7V9jxX_Ln-RTDfn-aeVJtnOzbfrAffCxlBJ9KIqe8CIQDIX-Z3RZOOrncb63WHwc9omViaGhI_xZ6PxHptNSgXHA==");
    String u2fRawRequest =
        JsonUtils.toJson(new RegisterInternalRequest(appParam, clientParam, version));

    when(receiver.forwardRequest(
            argThat(new PayloadMatcher(PayloadGenerateU2FKeyRequest.class)), eq(actor)))
        .thenReturn(createGenerateKeyResponse(encodedRandom, encodedKey, encodedCert));
    when(receiver.forwardRequest(argThat(new PayloadMatcher(PayloadSignRequest.class)), eq(actor)))
        .thenReturn(createSignResponse(signedHash));

    RegisterInternalResponse response =
        JsonUtils.fromJson(
            new RegisterInternalHandler(crysilForwarder).handle(u2fRawRequest, actor, receiver),
            RegisterInternalResponse.class);

    verify(crysilForwarder)
        .executeGenerateWrappedKey(
            eq(clientParam), eq(appParam), isNull(byte[].class), eq(actor), eq(receiver));
    verify(crysilForwarder)
        .executeSignatureRequest(eq(encodedKey), eq(hashToBeSigned), eq(actor), eq(receiver));

    assertThat(response.getRegistrationData(), is(registrationData));
  }
Exemplo n.º 2
0
  @Test
  public void testHandle() throws CertificateException {
    final CertificateFactory cf = CertificateFactory.getInstance("X.509");
    U2FReceiverInterface receiver = mock(U2FReceiverInterface.class);
    Module actor = mock(Module.class);
    String appId = "http://localhost:8081";
    byte[] challenge =
        BaseEncoding.base64Url().decode("zuiLwjPV5FNxLZDqivZGJOxZ-YRt045wgNeICI3TtVM");
    byte[] keyHandle =
        BaseEncoding.base64Url()
            .decode(
                "2KmIHW8wLzt_eW0Awry1NvfYV9pJVYhERjKwCzkSPG7KYFZScRV8h1z02DELcVhkEDAYFemMKLe-lPQFF2iyqaEsbCBYqLVx82FU8uuktcE-ZFAXyMjprN1jOoARJNRHvd1-nBYkn_plZFUW1X236U1izs0c7xf_4VWPuwI_m5BSyBmY_YKaIQdpGwToCYdcD_5NjaI76mTlHDWNt4f9Ug");
    String version = "U2F_V2";
    byte[] encodedRandom =
        BaseEncoding.base64()
            .decode(
                "2KmIHW8wLzt/eW0Awry1NvfYV9pJVYhERjKwCzkSPG7KYFZScRV8h1z02DELcVhkEDAYFemMKLe+lPQFF2iyqaEsbCBYqLVx82FU8uuktcE+ZFAXyMjprN1jOoARJNRHvd1+nBYkn/plZFUW1X236U1izs0c7xf/4VWPuwI/m5BSyBmY/YKaIQdpGwToCYdcD/5NjaI76mTlHDWNt4f9Ug==");
    byte[] encodedKey =
        BaseEncoding.base64()
            .decode(
                "MIIQ3gIBATEPMA0GCWCGSAFlAwQCAQUAMIILggYJKoZIhvcNAQcBoIILcwSCC28wggtrBgsqhkiG9w0BCRABF6CCC1owggtWAgEAMYIBZzCCAWMCAQAwSzBAMSIwIAYDVQQDExlJQUlLIFRlc3QgSW50ZXJtZWRpYXRlIENBMQ0wCwYDVQQKEwRJQUlLMQswCQYDVQQGEwJBVAIHARTz1EoFiDANBgkqhkiG9w0BAQEFAASCAQAJhWfH6gMHOJFUBKA5FZ9HaVFq4CRkriSH0VyQh2KB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fs5dxKQKYTxaKHK3w+Sq7mwKaxopgioJ4x4w9fq8+qdEYQWUaBTJiIVfBbJXdVkPD4xOnUFIbfxHqXn9DQHhAqQb0Ex3zt4Fo=");
    X509Certificate encodedCert =
        (X509Certificate)
            cf.generateCertificate(
                new ByteArrayInputStream(
                    BaseEncoding.base64()
                        .decode(
                            "MIICqDCCAZACIHCy6N/T8VQ8XOlp3EBkT9D1uw3uXMpuaIuwyYVtYdPRMA0GCSqGSIb3DQEBCwUAMIHMMQswCQYDVQQGEwJBVDENMAsGA1UEBxMER3JhejEmMCQGA1UEChMdR3JheiBVbml2ZXJzaXR5IG9mIFRlY2hub2xvZ3kxSDBGBgNVBAsTP0luc3RpdHV0ZSBmb3IgQXBwbGllZCBJbmZvcm1hdGlvbiBQcm9jZXNzaW5nIGFuZCBDb21tdW5pY2F0aW9uczESMBAGA1UEBBMJVGV1ZmwgRW5jMQ4wDAYDVQQqEwVQZXRlcjEYMBYGA1UEAxMPUGV0ZXIgVGV1ZmwgRW5jMB4XDTEzMDkwOTEwMzcxMloXDTIzMDkwOTEwMzcxMlowEzERMA8GA1UEAxMIU2t5VHJ1c3QwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAR+XOmSfxB8SU3A4PUmFB89awcIGnXLxBpnqHxltHLQg6evGeVhSmLqUDXYXKljHRpkITruRMVxlPZGREoTKFK8MA0GCSqGSIb3DQEBCwUAA4IBAQDC/ICTEa4sNE9paFCU8FJJ2o1eZ6Zzarx5jWtk6rd1KtB/jzQVvR/V4wq+3ItbEufdKh3HhHA2K9uEZm+Mu7t8FUaXFKAyksU2/PzI3kFUVsSoE7XiSuhyivUbT9xdWNTc4ZLJecrq5weJwkhoqLpW1ec1jGaFEpGMPlVGMJC8ANRGkc3ddeckAck8cdItR8wQ5ltEpiTklyoleIeTzu2kThl7mKc8CkqIiXcudNnKqY1USJ+Ns5jjLDStyy7+mLw45Y5p8U71Wmx2DEIkH/ExDWedMXIXdKvHD8BgTsbKNf70zZspwqMnDqThgi3Oio4VRWvKuszhmP++UZHoQobo")));
    byte[] hashToBeSigned =
        BaseEncoding.base64()
            .decode(
                "shPs6qCuWEVuIMbYe7LP6YJTAsuNm52zDg8ivpfq3P8BAAAAApx2KJNFlXnz0SLdmWN8Em1QffkLowUj0eBGfH5gvOxs");
    byte[] signedHash =
        BaseEncoding.base64()
            .decode(
                "MEUCIHp4kAVV2RqvELM1+Os0tNEPyA2li7GKhNYj93pUu4SpAiEAu6L6VdZsBcFmSUHVxAovRUYpXus2akMkGEaNsiQGb0o=");
    byte[] clientData =
        BaseEncoding.base64()
            .decode(
                "eyJvcmlnaW4iOiJodHRwOi8vbG9jYWxob3N0OjgwODEiLCJjaGFsbGVuZ2UiOiJ6dWlMd2pQVjVGTnhMWkRxaXZaR0pPeFotWVJ0MDQ1d2dOZUlDSTNUdFZNXHUwMDNkIiwidHlwIjoibmF2aWdhdG9yLmlkLmdldEFzc2VydGlvbiJ9");
    byte[] signatureData =
        BaseEncoding.base64Url()
            .decode(
                "AQAAAAIwRQIgeniQBVXZGq8QszX46zS00Q_IDaWLsYqE1iP3elS7hKkCIQC7ovpV1mwFwWZJQdXECi9FRile6zZqQyQYRo2yJAZvSg==");
    String u2fRawRequest = JsonUtils.toJson(new AuthRequest(appId, challenge, keyHandle, version));

    when(receiver.forwardRequest(
            argThat(new PayloadMatcher(PayloadGenerateU2FKeyRequest.class)), eq(actor)))
        .thenReturn(createGenerateKeyResponse(encodedRandom, encodedKey, encodedCert));
    when(receiver.forwardRequest(argThat(new PayloadMatcher(PayloadSignRequest.class)), eq(actor)))
        .thenReturn(createSignResponse(signedHash));

    AuthResponse response =
        JsonUtils.fromJson(
            new AuthenticateExternalHandler(
                    new AuthenticateInternalHandler(crysilForwarder, counterStore))
                .handle(u2fRawRequest, actor, receiver),
            AuthResponse.class);

    verify(crysilForwarder)
        .executeSignatureRequest(aryEq(encodedKey), aryEq(hashToBeSigned), eq(actor), eq(receiver));

    assertThat(response.getClientData(), is(clientData));
    assertThat(response.getChallenge(), is(challenge));
    assertThat(response.getKeyHandle(), is(keyHandle));
    assertThat(response.getSignatureData(), is(signatureData));
  }