https://github.com/tswayne/js-libtrust
Javascript implementation of libtrust
https://github.com/tswayne/js-libtrust
Last synced: 4 months ago
JSON representation
Javascript implementation of libtrust
- Host: GitHub
- URL: https://github.com/tswayne/js-libtrust
- Owner: tswayne
- License: mit
- Created: 2020-11-29T17:02:53.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2020-11-29T18:00:13.000Z (over 4 years ago)
- Last Synced: 2024-04-25T11:22:25.980Z (about 1 year ago)
- Language: JavaScript
- Size: 2.18 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# js-libtrust
Javascript implementation of docker's [libtrust](https://github.com/docker/libtrust) fingerprint, used for the key id header in the jwt used for dockr authentication. The implementation follows the spec outlined in
docker's [token authentication implementation](https://docs.docker.com/registry/spec/auth/jwt/):
```markdown
The “kid” field has to be in a libtrust fingerprint compatible format. Such a format can be generated by following steps:
1. Take the DER encoded public key which the JWT token was signed against.
2. Create a SHA256 hash out of it and truncate to 240bits.
3. Split the result into 12 base32 encoded groups with : as delimiter.
```## Usage
```javascript
const fs = require('fs')
const libtrust = require('libtrust')
const publicKey = fs.readFileSync('certificate.crt', 'utf-8')const keyId = libtrust.fingerprint(publicKey)
```### Shout out
Big shout out to @kyleburnett who cracked a few pieces to enable this javascript implementation.