<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>
GitLab
</title>


<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">
<div>
<p dir="auto">The static buffer problem with getpass still persists.</p>
<p dir="auto">You also need to copy the buffer pointed to by pin which is returned by getpass in pkcs11_set_token_pin, so its not overwritten by pin_callback's getpass:</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext"># p11tool --initialize-so-pin <url></span>
<span id="LC2" class="line" lang="plaintext">Setting admin's PIN...</span>
<span id="LC3" class="line" lang="plaintext">Enter Administrator's old PIN: 87654321                    "oldpin=getpass, copied to _oldpin"</span>
<span id="LC4" class="line" lang="plaintext">Enter Administrators's new PIN: 76543210                   "pin=getpass, not copied"</span>
<span id="LC5" class="line" lang="plaintext">Token 'swtok' with URL '<url>' requires security officer PIN</span>
<span id="LC6" class="line" lang="plaintext">Enter PIN: 87654321                                        "password=getpass, pin overwritten"</span>
<span id="LC7" class="line" lang="plaintext">Error in pkcs11_set_token_pin:1516: Error in provided PIN. "C_SetPIN fails since oldpin=newpin"</span></code></pre>
<p dir="auto">It would possibly be the best option to substitute all getpass occurences by something like the following wrapper (which still lacks thread-safety):</p>
<pre class="code highlight js-syntax-highlight plaintext" lang="plaintext" v-pre="true"><code><span id="LC1" class="line" lang="plaintext">int getpass_copy(char *pass, size_t passlen, const char *prompt) {</span>
<span id="LC2" class="line" lang="plaintext">    char tmp;</span>
<span id="LC3" class="line" lang="plaintext"></span>
<span id="LC4" class="line" lang="plaintext">    tmp = getpass(prompt);</span>
<span id="LC5" class="line" lang="plaintext">    if (tmp == NULL)</span>
<span id="LC6" class="line" lang="plaintext">        return SOME_ERROR;</span>
<span id="LC7" class="line" lang="plaintext"></span>
<span id="LC8" class="line" lang="plaintext">    if (strlen(tmp) >= passlen)</span>
<span id="LC9" class="line" lang="plaintext">        return SOME_ERROR;</span>
<span id="LC10" class="line" lang="plaintext"></span>
<span id="LC11" class="line" lang="plaintext">    strcpy(pass, tmp);</span>
<span id="LC12" class="line" lang="plaintext"></span>
<span id="LC13" class="line" lang="plaintext">    OPENSSL_cleanse(tmp, strlen(tmp));</span>
<span id="LC14" class="line" lang="plaintext">    return SUCCESS;</span>
<span id="LC15" class="line" lang="plaintext">}</span></code></pre>
</div>


</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #777777;">

<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/merge_requests/776#note_109670727">view it on GitLab</a>.
<br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can
<a href="https://gitlab.com/sent_notifications/952fa3b73989f27f11ec99dee1730d01/unsubscribe">unsubscribe</a>
from this thread or
adjust your notification settings.
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Merge request","url":"https://gitlab.com/gnutls/gnutls/merge_requests/776#note_109670727"}}</script>
</p>
</div>
</body>
</html>