2020-04-12 20:50:35 +02:00
<!doctype html>
< html class = "default no-js" >
< head >
< meta charset = "utf-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< title > fast-srp-hap< / title >
2021-01-10 18:00:26 +01:00
< meta name = "description" content = "Documentation for fast-srp-hap" >
2020-04-12 20:50:35 +02:00
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< link rel = "stylesheet" href = "assets/css/main.css" >
2021-01-10 18:00:26 +01:00
< script async src = "assets/js/search.js" id = "search-script" > < / script >
2020-04-12 20:50:35 +02:00
< / head >
< body >
< header >
< div class = "tsd-page-toolbar" >
< div class = "container" >
< div class = "table-wrap" >
2021-01-10 18:00:26 +01:00
< div class = "table-cell" id = "tsd-search" data-index = "assets/js/search.json" data-base = "." >
2020-04-12 20:50:35 +02:00
< div class = "field" >
< label for = "tsd-search-field" class = "tsd-widget search no-caption" > Search< / label >
< input id = "tsd-search-field" type = "text" / >
< / div >
< ul class = "results" >
< li class = "state loading" > Preparing search index...< / li >
< li class = "state failure" > The search index is not available< / li >
< / ul >
< a href = "index.html" class = "title" > fast-srp-hap< / a >
< / div >
< div class = "table-cell" id = "tsd-widgets" >
< div id = "tsd-filter" >
< a href = "#" class = "tsd-widget options no-caption" data-toggle = "options" > Options< / a >
< div class = "tsd-filter-group" >
< div class = "tsd-select" id = "tsd-filter-visibility" >
< span class = "tsd-select-label" > All< / span >
< ul class = "tsd-select-list" >
< li data-value = "public" > Public< / li >
< li data-value = "protected" > Public/Protected< / li >
< li data-value = "private" class = "selected" > All< / li >
< / ul >
< / div >
< input type = "checkbox" id = "tsd-filter-inherited" checked / >
< label class = "tsd-widget" for = "tsd-filter-inherited" > Inherited< / label >
< input type = "checkbox" id = "tsd-filter-externals" checked / >
< label class = "tsd-widget" for = "tsd-filter-externals" > Externals< / label >
< / div >
< / div >
< a href = "#" class = "tsd-widget menu no-caption" data-toggle = "menu" > Menu< / a >
< / div >
< / div >
< / div >
< / div >
< div class = "tsd-page-title" >
< div class = "container" >
2021-03-09 12:33:57 +01:00
< h1 > fast-srp-hap< / h1 >
2020-04-12 20:50:35 +02:00
< / div >
< / div >
< / header >
< div class = "container container-main" >
< div class = "row" >
< div class = "col-8 col-content" >
< div class = "tsd-panel tsd-typography" >
< a href = "#fast-srp-hap" id = "fast-srp-hap" style = "color: inherit; text-decoration: none;" >
< h1 > fast-srp-hap< / h1 >
< / a >
< p > < img src = "https://badgen.net/npm/v/fast-srp-hap" alt = "NPM-Version" >
< img src = "https://badgen.net/npm/dt/fast-srp-hap" alt = "NPM-Downloads" >
2021-01-10 18:00:26 +01:00
< img src = "https://github.com/homebridge/fast-srp/workflows/Node-CI/badge.svg" alt = "Node-CI" >
< a href = "https://coveralls.io/github/homebridge/fast-srp?branch=master" > < img src = "https://coveralls.io/repos/github/homebridge/fast-srp/badge.svg?branch=master" alt = "Coverage Status" > < / a > < / p >
2020-04-12 20:50:35 +02:00
< p > Is a pure < a href = "https://nodejs.org/" > NodeJS< / a > implementation of the < a href = "http://srp.stanford.edu/" > SRP6a protocol< / a > .< / p >
< p > It' s a derived work of < a href = "http://jedparsons.com/" > Jed Parson< / a > ' s < a href = "https://github.com/jedp/node-srp" > node-srp< / a > and < a href = "http://www-cs-students.stanford.edu/~tjw/" > Tom Wu< / a > ' s < a href = "http://www-cs-students.stanford.edu/~tjw/jsbn/" > jsbn< / a > .< / p >
2021-03-09 12:33:57 +01:00
< p > Full documentation can be found < a href = "https://developers.homebridge.io/fast-srp/modules.html" > here< / a > .< / p >
2020-04-12 20:50:35 +02:00
< a href = "#creating-the-verifier" id = "creating-the-verifier" style = "color: inherit; text-decoration: none;" >
< h2 > Creating the Verifier< / h2 >
< / a >
2021-01-10 18:00:26 +01:00
< pre > < code class = "language-ts" > < span style = "color: #AF00DB" > import< / span > < span style = "color: #000000" > { < / span > < span style = "color: #001080" > SRP< / span > < span style = "color: #000000" > } < / span > < span style = "color: #AF00DB" > from< / span > < span style = "color: #000000" > < / span > < span style = "color: #A31515" > ' fast-srp-hap' < / span > < span style = "color: #000000" > ;< / span >
2020-04-12 20:50:35 +02:00
2021-01-10 18:00:26 +01:00
< span style = "color: #008000" > /**< / span >
< span style = "color: #008000" > * Computes the verifier of a user. Only needed to add the user to the auth system.< / span >
< span style = "color: #008000" > *< / span >
< span style = "color: #008000" > * < / span > < span style = "color: #0000FF" > @param< / span > < span style = "color: #008000" > < / span > < span style = "color: #267F99" > {string}< / span > < span style = "color: #008000" > < / span > < span style = "color: #001080" > I< / span > < span style = "color: #008000" > Username to compute verifier< / span >
< span style = "color: #008000" > * < / span > < span style = "color: #0000FF" > @param< / span > < span style = "color: #008000" > < / span > < span style = "color: #267F99" > {string}< / span > < span style = "color: #008000" > < / span > < span style = "color: #001080" > P< / span > < span style = "color: #008000" > Password< / span >
< span style = "color: #008000" > * < / span > < span style = "color: #0000FF" > @return< / span > < span style = "color: #008000" > < / span > < span style = "color: #267F99" > {Promise< {salt: Buffer, verifier: Buffer}> }< / span >
< span style = "color: #008000" > */< / span >
< span style = "color: #0000FF" > async< / span > < span style = "color: #000000" > < / span > < span style = "color: #0000FF" > function< / span > < span style = "color: #000000" > < / span > < span style = "color: #795E26" > srp6a_create_user< / span > < span style = "color: #000000" > (< / span > < span style = "color: #001080" > I< / span > < span style = "color: #000000" > : < / span > < span style = "color: #267F99" > string< / span > < span style = "color: #000000" > , < / span > < span style = "color: #001080" > P< / span > < span style = "color: #000000" > : < / span > < span style = "color: #267F99" > string< / span > < span style = "color: #000000" > ) {< / span >
< span style = "color: #000000" > < / span > < span style = "color: #0000FF" > const< / span > < span style = "color: #000000" > < / span > < span style = "color: #0070C1" > salt< / span > < span style = "color: #000000" > = < / span > < span style = "color: #AF00DB" > await< / span > < span style = "color: #000000" > < / span > < span style = "color: #0070C1" > SRP< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > genKey< / span > < span style = "color: #000000" > (< / span > < span style = "color: #098658" > 32< / span > < span style = "color: #000000" > );< / span >
2021-03-09 12:33:57 +01:00
< span style = "color: #000000" > < / span >
2021-01-10 18:00:26 +01:00
< span style = "color: #000000" > < / span > < span style = "color: #AF00DB" > return< / span > < span style = "color: #000000" > {< / span >
< span style = "color: #000000" > < / span > < span style = "color: #008000" > // The salt is required for authenticating the user later< / span >
< span style = "color: #000000" > < / span > < span style = "color: #001080" > salt< / span > < span style = "color: #000000" > ,< / span >
< span style = "color: #000000" > < / span > < span style = "color: #001080" > verifier:< / span > < span style = "color: #000000" > < / span > < span style = "color: #0070C1" > SRP< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > computeVerifier< / span > < span style = "color: #000000" > (< / span > < span style = "color: #0070C1" > SRP< / span > < span style = "color: #000000" > .< / span > < span style = "color: #001080" > params< / span > < span style = "color: #000000" > [< / span > < span style = "color: #098658" > 4096< / span > < span style = "color: #000000" > ], < / span > < span style = "color: #001080" > salt< / span > < span style = "color: #000000" > , < / span > < span style = "color: #001080" > Buffer< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > from< / span > < span style = "color: #000000" > (< / span > < span style = "color: #0070C1" > I< / span > < span style = "color: #000000" > ), < / span > < span style = "color: #001080" > Buffer< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > from< / span > < span style = "color: #000000" > (< / span > < span style = "color: #0070C1" > P< / span > < span style = "color: #000000" > )),< / span >
< span style = "color: #000000" > };< / span >
< span style = "color: #000000" > }< / span >
2020-04-12 20:50:35 +02:00
2021-01-10 18:00:26 +01:00
< span style = "color: #AF00DB" > await< / span > < span style = "color: #000000" > < / span > < span style = "color: #795E26" > srp6a_create_user< / span > < span style = "color: #000000" > (< / span > < span style = "color: #A31515" > ' Zarmack Tanen' < / span > < span style = "color: #000000" > , < / span > < span style = "color: #A31515" > ' *****' < / span > < span style = "color: #000000" > ).< / span > < span style = "color: #795E26" > then< / span > < span style = "color: #000000" > (({< / span > < span style = "color: #001080" > salt< / span > < span style = "color: #000000" > , < / span > < span style = "color: #001080" > verifier< / span > < span style = "color: #000000" > }) < / span > < span style = "color: #0000FF" > => < / span > < span style = "color: #000000" > {< / span >
< span style = "color: #000000" > < / span > < span style = "color: #001080" > console< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > log< / span > < span style = "color: #000000" > (< / span > < span style = "color: #A31515" > ' SRP6a verifier and salt of Zarmack Tanen user is %s and %s' < / span > < span style = "color: #000000" > ,< / span >
< span style = "color: #000000" > < / span > < span style = "color: #001080" > verifier< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > toString< / span > < span style = "color: #000000" > (< / span > < span style = "color: #A31515" > ' hex' < / span > < span style = "color: #000000" > ), < / span > < span style = "color: #001080" > salt< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > toString< / span > < span style = "color: #000000" > (< / span > < span style = "color: #A31515" > ' hex' < / span > < span style = "color: #000000" > ));< / span >
< span style = "color: #000000" > });< / span >
< / code > < / pre >
2020-04-12 20:50:35 +02:00
< a href = "#server" id = "server" style = "color: inherit; text-decoration: none;" >
< h2 > Server< / h2 >
< / a >
2021-01-10 18:00:26 +01:00
< pre > < code class = "language-ts" > < span style = "color: #AF00DB" > import< / span > < span style = "color: #000000" > {< / span > < span style = "color: #001080" > SRP< / span > < span style = "color: #000000" > , < / span > < span style = "color: #001080" > SrpServer< / span > < span style = "color: #000000" > } < / span > < span style = "color: #AF00DB" > from< / span > < span style = "color: #000000" > < / span > < span style = "color: #A31515" > ' fast-srp-hap' < / span > < span style = "color: #000000" > ;< / span >
2020-04-12 20:50:35 +02:00
2021-01-10 18:00:26 +01:00
< span style = "color: #000000" > (< / span > < span style = "color: #0000FF" > async< / span > < span style = "color: #000000" > () < / span > < span style = "color: #0000FF" > => < / span > < span style = "color: #000000" > {< / span >
< span style = "color: #000000" > < / span > < span style = "color: #008000" > // Get the user details from somewhere< / span >
< span style = "color: #000000" > < / span > < span style = "color: #0000FF" > const< / span > < span style = "color: #000000" > < / span > < span style = "color: #0070C1" > user< / span > < span style = "color: #000000" > = {< / span >
< span style = "color: #000000" > < / span > < span style = "color: #001080" > username:< / span > < span style = "color: #000000" > < / span > < span style = "color: #A31515" > ' username' < / span > < span style = "color: #000000" > , < / span > < span style = "color: #008000" > // Or a Buffer< / span >
2020-04-12 20:50:35 +02:00
2021-01-10 18:00:26 +01:00
< span style = "color: #000000" > < / span > < span style = "color: #008000" > // If we have the plaintext password< / span >
< span style = "color: #000000" > < / span > < span style = "color: #001080" > salt:< / span > < span style = "color: #000000" > < / span > < span style = "color: #AF00DB" > await< / span > < span style = "color: #000000" > < / span > < span style = "color: #0070C1" > SRP< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > genKey< / span > < span style = "color: #000000" > (< / span > < span style = "color: #098658" > 32< / span > < span style = "color: #000000" > ),< / span >
< span style = "color: #000000" > < / span > < span style = "color: #001080" > password:< / span > < span style = "color: #000000" > < / span > < span style = "color: #A31515" > ' password' < / span > < span style = "color: #000000" > , < / span > < span style = "color: #008000" > // Or a Buffer< / span >
2021-03-09 12:33:57 +01:00
< span style = "color: #000000" > < / span >
2021-01-10 18:00:26 +01:00
< span style = "color: #000000" > < / span > < span style = "color: #008000" > // If we have a saved verifier< / span >
< span style = "color: #000000" > < / span > < span style = "color: #001080" > salt:< / span > < span style = "color: #000000" > < / span > < span style = "color: #001080" > Buffer< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > from< / span > < span style = "color: #000000" > (< / span > < span style = "color: #A31515" > ' ...' < / span > < span style = "color: #000000" > ),< / span >
< span style = "color: #000000" > < / span > < span style = "color: #001080" > verifier:< / span > < span style = "color: #000000" > < / span > < span style = "color: #001080" > Buffer< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > from< / span > < span style = "color: #000000" > (< / span > < span style = "color: #A31515" > ' ...' < / span > < span style = "color: #000000" > ),< / span >
< span style = "color: #000000" > };< / span >
2020-04-12 20:50:35 +02:00
2021-01-10 18:00:26 +01:00
< span style = "color: #000000" > < / span > < span style = "color: #008000" > // Generate a secret key< / span >
< span style = "color: #000000" > < / span > < span style = "color: #0000FF" > const< / span > < span style = "color: #000000" > < / span > < span style = "color: #0070C1" > secret< / span > < span style = "color: #000000" > = < / span > < span style = "color: #AF00DB" > await< / span > < span style = "color: #000000" > < / span > < span style = "color: #0070C1" > SRP< / span > < span style = "color: #000000" > .< / span > < span style = "color: #795E26" > genKey< / span > < span style = "color: #000000" > (< / span > < span style = "color: #098658" > 32< / span > < span style = "color: #000000" > );< / span >
2020-04-12 20:50:35 +02:00
2021-03-09 12:33:57 +01:00
< span style = "color: #000000" > < / span > < span style = "color: #0000FF" > const< / span > < span style = "color: #000000" > < / span > < span style = "color: #0070C1" > server< / span > < span style = "color: #000000" > = < / span > < span style = "color: #0000FF" > new< / span > < span style = "color: #000000" > < / span > < span style = "color: #795E26" > SrpServer< / span > < span style = "color: #000000" > (< / span > < span style = "color: #0070C1" > SRP< / span > < span style = "color: #000000" > .< / span > < span style = "color: #001080" > params< / span > < span style = "color: #000000" > [< / span > < span style = "color: #098658" > 3076< / span > < span style = "color: #000000" > ], < / span > < span style = "color: #001080" > user< / span > < span style = "color: #000000" > , < / span > < span style = "color: #001080" > secret< / span > < span style = "color: #000000" > ); < / span > < span style = "color: #008000" > // For Apple SRP use params.hap< / span >
2020-04-12 20:50:35 +02:00
2021-01-10 18:00:26 +01:00
< span style = "color: #000000" > < / span > < span style = "color: #008000" > // ...< / span >
< span style = "color: #000000" > })();< / span >
< / code > < / pre >
2020-04-12 20:50:35 +02:00
< / div >
< / div >
< div class = "col-4 col-menu menu-sticky-wrap menu-highlight" >
< nav class = "tsd-navigation primary" >
< ul >
2021-01-10 18:00:26 +01:00
< li class = " " >
< a href = "modules.html" > Exports< / a >
2020-04-12 20:50:35 +02:00
< / li >
< / ul >
< / nav >
< nav class = "tsd-navigation secondary menu-sticky" >
< ul class = "before-current" >
< li class = " tsd-kind-class" >
< a href = "classes/srp.html" class = "tsd-kind-icon" > SRP< / a >
< / li >
< li class = " tsd-kind-class" >
< a href = "classes/srpclient.html" class = "tsd-kind-icon" > Srp< wbr > Client< / a >
< / li >
< li class = " tsd-kind-class" >
< a href = "classes/srpserver.html" class = "tsd-kind-icon" > Srp< wbr > Server< / a >
< / li >
< li class = " tsd-kind-interface" >
< a href = "interfaces/baseidentity.html" class = "tsd-kind-icon" > Base< wbr > Identity< / a >
< / li >
< li class = " tsd-kind-interface" >
< a href = "interfaces/srpparams.html" class = "tsd-kind-icon" > Srp< wbr > Params< / a >
< / li >
< li class = " tsd-kind-type-alias" >
2021-01-10 18:00:26 +01:00
< a href = "modules.html#genkeycallback" class = "tsd-kind-icon" > Gen< wbr > Key< wbr > Callback< / a >
2020-04-12 20:50:35 +02:00
< / li >
< li class = " tsd-kind-type-alias" >
2021-01-10 18:00:26 +01:00
< a href = "modules.html#identity" class = "tsd-kind-icon" > Identity< / a >
2020-04-12 20:50:35 +02:00
< / li >
< li class = " tsd-kind-type-alias" >
2021-01-10 18:00:26 +01:00
< a href = "modules.html#passwordidentity" class = "tsd-kind-icon" > Password< wbr > Identity< / a >
2020-04-12 20:50:35 +02:00
< / li >
< li class = " tsd-kind-type-alias" >
2021-01-10 18:00:26 +01:00
< a href = "modules.html#verifieridentity" class = "tsd-kind-icon" > Verifier< wbr > Identity< / a >
2020-04-12 20:50:35 +02:00
< / li >
< / ul >
< / nav >
< / div >
< / div >
< / div >
< footer >
< div class = "container" >
< h2 > Legend< / h2 >
< div class = "tsd-legend-group" >
< ul class = "tsd-legend" >
< li class = "tsd-kind-constructor tsd-parent-kind-class" > < span class = "tsd-kind-icon" > Constructor< / span > < / li >
< li class = "tsd-kind-property tsd-parent-kind-class" > < span class = "tsd-kind-icon" > Property< / span > < / li >
< li class = "tsd-kind-method tsd-parent-kind-class" > < span class = "tsd-kind-icon" > Method< / span > < / li >
< / ul >
< ul class = "tsd-legend" >
2021-01-10 18:00:26 +01:00
< li class = "tsd-kind-property tsd-parent-kind-class tsd-is-static" > < span class = "tsd-kind-icon" > Static property< / span > < / li >
< li class = "tsd-kind-method tsd-parent-kind-class tsd-is-static" > < span class = "tsd-kind-icon" > Static method< / span > < / li >
2020-04-12 20:50:35 +02:00
< / ul >
< ul class = "tsd-legend" >
2021-01-10 18:00:26 +01:00
< li class = "tsd-kind-property tsd-parent-kind-interface" > < span class = "tsd-kind-icon" > Property< / span > < / li >
2020-04-12 20:50:35 +02:00
< / ul >
< / div >
< / div >
< / footer >
< div class = "overlay" > < / div >
< script src = "assets/js/main.js" > < / script >
< / body >
< / html >