1
0
mirror of https://github.com/danog/fast-srp.git synced 2024-11-26 20:04:49 +01:00
fast-srp/docs/index.html
2020-04-12 20:50:35 +02:00

233 lines
13 KiB
HTML

<!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>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.js" data-base=".">
<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">
<ul class="tsd-breadcrumb">
<li>
<a href="globals.html">Globals</a>
</li>
</ul>
<h1>fast-srp-hap</h1>
</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">
<img src="https://github.com/homebridge/fast-srp/workflows/Node-CI/badge.svg" alt="Node-CI"></p>
<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&#39;s a derived work of <a href="http://jedparsons.com/">Jed Parson</a>&#39;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>&#39;s <a href="http://www-cs-students.stanford.edu/~tjw/jsbn/">jsbn</a>.</p>
<a href="#creating-the-verifier" id="creating-the-verifier" style="color: inherit; text-decoration: none;">
<h2>Creating the Verifier</h2>
</a>
<pre><code class="language-ts"><span class="hljs-keyword">import</span> { SRP } <span class="hljs-keyword">from</span> <span class="hljs-string">'fast-srp-hap'</span>;
<span class="hljs-comment">/**
* Computes the verifier of a user. Only needed to add the user to the auth system.
*
* @param {string} I Username to compute verifier
* @param {string} P Password
* @return {Promise&lt;{salt: Buffer, verifier: Buffer}&gt;}
*/</span>
<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">srp6a_create_user</span>(<span class="hljs-params">I: <span class="hljs-built_in">string</span>, P: <span class="hljs-built_in">string</span></span>) </span>{
<span class="hljs-keyword">const</span> salt = <span class="hljs-keyword">await</span> SRP.genKey(<span class="hljs-number">32</span>);
<span class="hljs-keyword">return</span> {
<span class="hljs-comment">// The salt is required for authenticating the user later</span>
salt,
verifier: SRP.computeVerifier(SRP.params[<span class="hljs-number">4096</span>], salt, Buffer.from(I), Buffer.from(P)),
};
}
<span class="hljs-keyword">await</span> srp6a_create_user(<span class="hljs-string">'Zarmack Tanen'</span>, <span class="hljs-string">'*****'</span>).then(<span class="hljs-function">(<span class="hljs-params">{salt, verifier}</span>) =&gt;</span> {
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'SRP6a verifier and salt of Zarmack Tanen user is %s and %s'</span>,
verifier.toString(<span class="hljs-string">'hex'</span>), salt.toString(<span class="hljs-string">'hex'</span>));
});</code></pre>
<a href="#server" id="server" style="color: inherit; text-decoration: none;">
<h2>Server</h2>
</a>
<pre><code class="language-ts"><span class="hljs-keyword">import</span> {SRP, SrpServer} <span class="hljs-keyword">from</span> <span class="hljs-string">'fast-srp-hap'</span>;
<span class="hljs-function">(<span class="hljs-params"><span class="hljs-keyword">async</span> (<span class="hljs-params"></span>) =&gt; {
<span class="hljs-comment">// Get the user details from somewhere</span>
<span class="hljs-keyword">const</span> user = {
username: 'username', <span class="hljs-comment">// Or a Buffer</span>
<span class="hljs-comment">// If we have the plaintext password</span>
salt: <span class="hljs-keyword">await</span> SRP.genKey(<span class="hljs-params">32</span>),
password: 'password', <span class="hljs-comment">// Or a Buffer</span>
<span class="hljs-comment">// If we have a saved verifier</span>
salt: Buffer.<span class="hljs-keyword">from</span>(<span class="hljs-params">'...'</span>),
verifier: Buffer.<span class="hljs-keyword">from</span>(<span class="hljs-params">'...'</span>),
};
<span class="hljs-comment">// Generate a secret key</span>
<span class="hljs-keyword">const</span> secret = <span class="hljs-keyword">await</span> SRP.genKey(<span class="hljs-params">32</span>);
<span class="hljs-keyword">const</span> server = <span class="hljs-keyword">new</span> SrpServer(<span class="hljs-params">SRP.params[3076], user, secret</span>); <span class="hljs-comment">// For Apple SRP use params.hap</span>
<span class="hljs-comment">// ...</span>
}</span>)<span class="hljs-params">()</span>;</span></code></pre>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class="globals ">
<a href="globals.html"><em>Globals</em></a>
</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">
<a href="globals.html#genkeycallback" class="tsd-kind-icon">Gen<wbr>Key<wbr>Callback</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="globals.html#identity" class="tsd-kind-icon">Identity</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="globals.html#passwordidentity" class="tsd-kind-icon">Password<wbr>Identity</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="globals.html#verifieridentity" class="tsd-kind-icon">Verifier<wbr>Identity</a>
</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-module"><span class="tsd-kind-icon">Module</span></li>
<li class="tsd-kind-object-literal"><span class="tsd-kind-icon">Object literal</span></li>
<li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li>
<li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li>
<li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li>
<li class="tsd-kind-index-signature"><span class="tsd-kind-icon">Index signature</span></li>
<li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li>
<li class="tsd-kind-type-alias tsd-has-type-parameter"><span class="tsd-kind-icon">Type alias with type parameter</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li>
<li class="tsd-kind-enum-member"><span class="tsd-kind-icon">Enumeration member</span></li>
<li class="tsd-kind-property tsd-parent-kind-enum"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-enum"><span class="tsd-kind-icon">Method</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li>
<li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li>
<li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-interface"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li>
<li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li>
<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>
<li class="tsd-kind-accessor tsd-parent-kind-class"><span class="tsd-kind-icon">Accessor</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-class"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private accessor</span></li>
</ul>
<ul class="tsd-legend">
<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-call-signature tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
</ul>
</div>
</div>
</footer>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
<script>if (location.protocol == 'file:') document.write('<script src="assets/js/search.js"><' + '/script>');</script>
</body>
</html>