-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TLSA, SMIMEA: add BIND support (#13)
- Loading branch information
Showing
9 changed files
with
283 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
const RR = require('./index').RR | ||
|
||
class SMIMEA extends RR { | ||
constructor (opts) { | ||
super(opts) | ||
} | ||
|
||
/****** Resource record specific setters *******/ | ||
setCertificateUsage (val) { | ||
if (![ 0,1,2,3 ].includes(val)) | ||
throw new Error(`SMIMEA: certificate usage invalid, see ${this.getRFCs()}`) | ||
|
||
this.set('certificate usage', val) | ||
} | ||
|
||
setSelector (val) { | ||
if (![ 0,1 ].includes(val)) | ||
throw new Error(`SMIMEA: selector invalid, see ${this.getRFCs()}`) | ||
|
||
this.set('selector', val) | ||
} | ||
|
||
setMatchingType (val) { | ||
if (![ 0,1,2 ].includes(val)) | ||
throw new Error(`SMIMEA: matching type, see ${this.getRFCs()}`) | ||
|
||
this.set('matching type', val) | ||
} | ||
|
||
setCertificateAssociationData (val) { | ||
this.set('certificate association data', val) | ||
} | ||
|
||
|
||
getDescription () { | ||
return 'S/MIME cert association' | ||
} | ||
|
||
getRdataFields (arg) { | ||
return [ 'certificate usage', 'selector', 'matching type', 'certificate association data' ] | ||
} | ||
|
||
getRFCs () { | ||
return [ 8162 ] | ||
} | ||
|
||
getTypeId () { | ||
return 53 | ||
} | ||
|
||
getQuotedFields () { | ||
return [ ] | ||
} | ||
|
||
/****** IMPORTERS *******/ | ||
// fromTinydns (str) { | ||
// } | ||
|
||
fromBind (str) { | ||
// test.example.com 3600 IN SMIMEA, usage, selector, match, data | ||
const [ fqdn, ttl, c, type, usage, selector, match ] = str.split(/\s+/) | ||
return new this.constructor({ | ||
name : fqdn, | ||
ttl : parseInt(ttl, 10), | ||
class : c, | ||
type : type, | ||
'certificate usage' : parseInt(usage, 10), | ||
selector : parseInt(selector, 10), | ||
'matching type' : parseInt(match , 10), | ||
'certificate association data': str.split(/\s+/).slice(7).join(' ').trim(), | ||
}) | ||
} | ||
|
||
/****** EXPORTERS *******/ | ||
// toTinydns () { | ||
// } | ||
} | ||
|
||
module.exports = SMIMEA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
const RR = require('./index').RR | ||
|
||
class TLSA extends RR { | ||
constructor (opts) { | ||
super(opts) | ||
} | ||
|
||
/****** Resource record specific setters *******/ | ||
setCertificateUsage (val) { | ||
if (![ 0,1,2,3 ].includes(val)) | ||
throw new Error(`TLSA: certificate usage invalid, see ${this.getRFCs()}`) | ||
|
||
this.set('certificate usage', val) | ||
} | ||
|
||
setSelector (val) { | ||
if (![ 0,1 ].includes(val)) | ||
throw new Error(`TLSA: selector invalid, see ${this.getRFCs()}`) | ||
|
||
this.set('selector', val) | ||
} | ||
|
||
setMatchingType (val) { | ||
if (![ 0,1,2 ].includes(val)) | ||
throw new Error(`TLSA: matching type, see ${this.getRFCs()}`) | ||
|
||
this.set('matching type', val) | ||
} | ||
|
||
setCertificateAssociationData (val) { | ||
this.set('certificate association data', val) | ||
} | ||
|
||
getDescription () { | ||
return 'TLSA certificate association' | ||
} | ||
|
||
getRdataFields (arg) { | ||
return [ 'certificate usage', 'selector', 'matching type', 'certificate association data' ] | ||
} | ||
|
||
getRFCs () { | ||
return [ 6698 ] | ||
} | ||
|
||
getTypeId () { | ||
return 52 | ||
} | ||
|
||
getQuotedFields () { | ||
return [ ] | ||
} | ||
|
||
/****** IMPORTERS *******/ | ||
// fromTinydns (str) { | ||
// } | ||
|
||
fromBind (str) { | ||
// test.example.com 3600 IN TLSA, usage, selector, match, data | ||
const [ fqdn, ttl, c, type, usage, selector, match ] = str.split(/\s+/) | ||
return new this.constructor({ | ||
name : fqdn, | ||
ttl : parseInt(ttl, 10), | ||
class : c, | ||
type : type, | ||
'certificate usage' : parseInt(usage, 10), | ||
selector : parseInt(selector, 10), | ||
'matching type' : parseInt(match , 10), | ||
'certificate association data': str.split(/\s+/).slice(7).join(' ').trim(), | ||
}) | ||
} | ||
|
||
/****** EXPORTERS *******/ | ||
// toTinydns () { | ||
// } | ||
} | ||
|
||
module.exports = TLSA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
// const assert = require('assert') | ||
|
||
const base = require('./base') | ||
|
||
const SMIMEA = require('../rr/tlsa') | ||
|
||
const validRecords = [ | ||
{ | ||
class : 'IN', | ||
name : '_443._tcp.www.example.com', | ||
type : 'SMIMEA', | ||
ttl : 3600, | ||
'certificate usage' : 0, | ||
selector : 0, | ||
'matching type' : 1, | ||
'certificate association data': '( d2abde240d7cd3ee6b4b28c54df034b9 7983a1d16e8a410e4561cb106618e971 )', | ||
testB : '_443._tcp.www.example.com\t3600\tIN\tSMIMEA\t0\t0\t1\t( d2abde240d7cd3ee6b4b28c54df034b9 7983a1d16e8a410e4561cb106618e971 )\n', | ||
// testT : '', | ||
}, | ||
] | ||
|
||
const invalidRecords = [ | ||
{ | ||
// name : 'test.example.com', | ||
selector: 6, // invalid | ||
}, | ||
] | ||
|
||
describe('SMIMEA record', function () { | ||
base.valid(SMIMEA, validRecords, { ttl: 3600 }) | ||
base.invalid(SMIMEA, invalidRecords, { ttl: 3600 }) | ||
|
||
base.getDescription(SMIMEA) | ||
base.getRFCs(SMIMEA, validRecords[0]) | ||
base.getFields(SMIMEA, [ 'certificate usage', 'selector', 'matching type', 'certificate association data' ]) | ||
base.getTypeId(SMIMEA, 52) | ||
|
||
base.toBind(SMIMEA, validRecords) | ||
// base.toTinydns(SMIMEA, validRecords) | ||
|
||
base.fromBind(SMIMEA, validRecords) | ||
// base.fromTinydns(SMIMEA, validRecords) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
|
||
// const assert = require('assert') | ||
|
||
const base = require('./base') | ||
|
||
const TLSA = require('../rr/tlsa') | ||
|
||
const validRecords = [ | ||
{ | ||
class : 'IN', | ||
name : '_443._tcp.www.example.com', | ||
type : 'TLSA', | ||
ttl : 3600, | ||
'certificate usage' : 0, | ||
selector : 0, | ||
'matching type' : 1, | ||
'certificate association data': '( d2abde240d7cd3ee6b4b28c54df034b9 7983a1d16e8a410e4561cb106618e971 )', | ||
testB : '_443._tcp.www.example.com\t3600\tIN\tTLSA\t0\t0\t1\t( d2abde240d7cd3ee6b4b28c54df034b9 7983a1d16e8a410e4561cb106618e971 )\n', | ||
// testT : '', | ||
}, | ||
{ | ||
class : 'IN', | ||
name : '_443._tcp.www.example.com', | ||
type : 'TLSA', | ||
ttl : 3600, | ||
'certificate usage' : 1, | ||
selector : 1, | ||
'matching type' : 2, | ||
'certificate association data': '( 92003ba34942dc74152e2f2c408d29ec a5a520e7f2e06bb944f4dca346baf63c 1b177615d466f6c4b71c216a50292bd5 8c9ebdd2f74e38fe51ffd48c43326cbc )', | ||
testB : `_443._tcp.www.example.com\t3600\tIN\tTLSA\t1\t1\t2\t( 92003ba34942dc74152e2f2c408d29ec a5a520e7f2e06bb944f4dca346baf63c 1b177615d466f6c4b71c216a50292bd5 8c9ebdd2f74e38fe51ffd48c43326cbc )\n`, | ||
testT : '', | ||
}, | ||
] | ||
|
||
const invalidRecords = [ | ||
{ | ||
// name : 'test.example.com', | ||
selector: 6, // invalid | ||
}, | ||
] | ||
|
||
describe('TLSA record', function () { | ||
base.valid(TLSA, validRecords) | ||
base.invalid(TLSA, invalidRecords, { ttl: 3600 }) | ||
|
||
base.getDescription(TLSA) | ||
base.getRFCs(TLSA, validRecords[0]) | ||
base.getFields(TLSA, [ 'certificate usage', 'selector', 'matching type', 'certificate association data' ]) | ||
base.getTypeId(TLSA, 52) | ||
|
||
base.toBind(TLSA, validRecords) | ||
// base.toTinydns(TLSA, validRecords) | ||
|
||
base.fromBind(TLSA, validRecords) | ||
// base.fromTinydns(TLSA, validRecords) | ||
}) |