Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Android SafetyNet #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

eheikes
Copy link
Contributor

@eheikes eheikes commented Jan 16, 2020

What It Does

This PR adds support for the android-safetynet attestation format to the server package. It should close #24.

Details

parseAndroidSafetyNetKey() follows the process outlined in the WebAuthn specs and the SafetyNet docs. validateAndroidSafetyNetKey() and parseAttestationData() basically duplicates the code from the other formats, since it's the same routine for all.

The original implementation in our fork has been tested and will be used in production soon. This PR takes code & ideas from @tnokin's fork to improve upon the original code.

How To Test

You can test against a real-world example:

const parseRegisterRequest = require('./packages/server/src/registration').parseRegisterRequest
const body = {
    "id": "Acy1doxPENsOlmfL8xOLpWEIrjYQ67ADfnL5P0Nzjszt-QGl_x4-48MP1yiMVOxKZqGLti4Ppkr3WYF-OXcv840",
    "rawId": "Acy1doxPENsOlmfL8xOLpWEIrjYQ67ADfnL5P0Nzjszt-QGl_x4-48MP1yiMVOxKZqGLti4Ppkr3WYF-OXcv840",
    "type": "public-key",
    "response": {
        "attestationObject": "o2NmbXRxYW5kcm9pZC1zYWZldHluZXRnYXR0U3RtdKJjdmVyaDE5NDIwMDQ4aHJlc3BvbnNlWRTCZXlKaGJHY2lPaUpTVXpJMU5pSXNJbmcxWXlJNld5Sk5TVWxHYkVSRFEwSkllV2RCZDBsQ1FXZEpVa0ZOYTJKNk1tOUdhaXRuYVVOQlFVRkJRVUZXWkdZd2QwUlJXVXBMYjFwSmFIWmpUa0ZSUlV4Q1VVRjNVV3BGVEUxQmEwZEJNVlZGUW1oTlExWldUWGhJYWtGalFtZE9Wa0pCYjFSR1ZXUjJZakprYzFwVFFsVmpibFo2WkVOQ1ZGcFlTakpoVjA1c1kzcEZWRTFDUlVkQk1WVkZRWGhOUzFJeFVsUkpSVTVDU1VSR1V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xWlgwLmpsc25yb1g3bXRPLXZROUM4SGNhaFFZRHJENHdJZ1RUNFBzRmI5bWthcml5dUNBV1BwWDNNYlhILVhNZ1VGMmdWdEVFX3B5S2prMUhiOXJKdk1LS0JCb2FoOTR3dTlwbEt3akVPa2xmaWtuelp5VzgyNUh2T05GMmhaTDlsazd2NXZUeUhMeGVpMGxUejZmSTBILUR6b0RXeDF6QXFzOC1vbF9PekhBMzU2R3pRcFg2WlJ0Sk43aUF0QUkzOXVoeGVhSkk5ZWQwM2lGaFRxY1BfYXJSZnBDWjJHUEp0QWVBRFFQWWRhdDNYQ05VYm4zWEpnZ0xfZHNTaUlwazFxSFduNlZvcXpUMk9QTFF6NjdYYXp1RGV4bGF5SXFQLWFhTFc5TjJKYXE4NDBXVWdLZGFLNE1FSWxvVFBVWmNnSi1nRjFMdjJxUm9fUjRvVkhNVEt6M3EzZ2hhdXRoRGF0YVjFSZYN5YgOjGh0NBcPZHZgW4/krrmihjLHmVzzuoMdl2NFAAAAALk/2WHy5kYvsSKCACJH3ngAQQHMtXaMTxDbDpZny/MTi6VhCK42EOuwA35y+T9Dc47M7fkBpf8ePuPDD9cojFTsSmahi7YuD6ZK91mBfjl3L/ONpQECAyYgASFYIDbKMSzPmXLUnE5smSCzWtDjYqxbrUcjaqjLteSBPxylIlggKShBQQRSLimme/nNu3dxm8K1YH+1VA3/CgisT1Ck8Yw=",
        "clientDataJSON": "eyJ0eXBlIjoid2ViYXV0aG4uY3JlYXRlIiwiY2hhbGxlbmdlIjoiMk4zelNBWFZLdTJtQkdxV3VWQnozd2xFODdjT1Q2RHdPNUJoTnZ6amJSQSIsIm9yaWdpbiI6Imh0dHBzOlwvXC9sb2NhbGhvc3Q6ODQ0MyIsImFuZHJvaWRQYWNrYWdlTmFtZSI6ImNvbS5hbmRyb2lkLmNocm9tZSJ9"
    }
}
console.log(parseRegisterRequest(body))

Running this should result in:

{ challenge: '2N3zSAXVKu2mBGqWuVBz3wlE87cOT6DwO5BhNvzjbRA=',
  key:
   { fmt: 'android-safetynet',
     publicKey:
      'BDbKMSzPmXLUnE5smSCzWtDjYqxbrUcjaqjLteSBPxylKShBQQRSLimme/nNu3dxm8K1YH+1VA3/CgisT1Ck8Yw=',
     counter: 0,
     credID:
      'Acy1doxPENsOlmfL8xOLpWEIrjYQ67ADfnL5P0Nzjszt+QGl/x4+48MP1yiMVOxKZqGLti4Ppkr3WYF+OXcv840=' } }

@eheikes eheikes mentioned this pull request Jan 16, 2020
@eheikes
Copy link
Contributor Author

eheikes commented Jan 23, 2020

@Kmaschta Can this be merged?

@gustavobini
Copy link

Any follow up on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

android-safetynet
3 participants