<!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=US-ASCII" http-equiv="Content-Type">
<title>
GitLab
</title>



<style>img {
max-width: 100%; height: auto;
}
</style>
</head>
<body>
<div class="content">

<p style="color: #777777;">
<a href="https://gitlab.com/trapperhoney">Craig</a>
commented on a
discussion on <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1459#note_649760962">lib/x509/privkey.c</a>:
</p>
<table>
<tr class="line_holder" id="">
<td class="old_line diff-line-num" data-linenumber="754" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
754
</td>
<td class="new_line diff-line-num" data-linenumber="754" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
754
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;">
<pre style="margin: 0;"> <span id="LC754" class="line" lang="c">                <span class="n" style="color: #333;">password</span> <span class="o" style="font-weight: 600;">==</span> <span class="nb" style="color: #0086b3;">NULL</span> <span class="o" style="font-weight: 600;">&&</span> <span class="p">(</span><span class="o" style="font-weight: 600;">!</span><span class="p">(</span><span class="n" style="color: #333;">flags</span> <span class="o" style="font-weight: 600;">&</span> <span class="n" style="color: #333;">GNUTLS_PKCS_PLAIN</span><span class="p">)))</span> <span class="p">{</span></span>
</pre>
</td>
</tr>
<tr class="line_holder" id="">
<td class="old_line diff-line-num" data-linenumber="755" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
755
</td>
<td class="new_line diff-line-num" data-linenumber="755" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
755
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;">
<pre style="margin: 0;"> <span id="LC755" class="line" lang="c">                <span class="cm" style="color: #998; font-style: italic;">/* use the callback if any */</span></span>
</pre>
</td>
</tr>
<tr class="line_holder" id="">
<td class="old_line diff-line-num" data-linenumber="756" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
756
</td>
<td class="new_line diff-line-num" data-linenumber="756" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
756
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;">
<pre style="margin: 0;"> <span id="LC756" class="line" lang="c">                    <span class="n" style="color: #333;">ret</span> <span class="o" style="font-weight: 600;">=</span> <span class="n" style="color: #333;">_gnutls_retrieve_pin</span><span class="p">(</span><span class="o" style="font-weight: 600;">&</span><span class="n" style="color: #333;">key</span><span class="o" style="font-weight: 600;">-></span><span class="n" style="color: #333;">pin</span><span class="p">,</span> <span class="s" style="color: #d14;">"key:"</span><span class="p">,</span> <span class="s" style="color: #d14;">""</span><span class="p">,</span> <span class="mi" style="color: #099;">0</span><span class="p">,</span> <span class="n" style="color: #333;">pin</span><span class="p">,</span> <span class="k" style="font-weight: 600;">sizeof</span><span class="p">(</span><span class="n" style="color: #333;">pin</span><span class="p">));</span></span>
</pre>
</td>
</tr>
<tr class="line_holder" id="">
<td class="old_line diff-line-num" data-linenumber="757" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
757
</td>
<td class="new_line diff-line-num" data-linenumber="757" style="width: 35px; color: rgba(0,0,0,0.3); border-right-width: 1px; border-right-color: #f0f0f0; border-right-style: solid; padding: 0 5px;" align="right" bgcolor="#fafafa">
757
</td>
<td class="line_content" style="padding-left: 0.5em; padding-right: 0.5em;">
<pre style="margin: 0;"> <span id="LC757" class="line" lang="c">                    <span class="k" style="font-weight: 600;">if</span> <span class="p">(</span><span class="n" style="color: #333;">ret</span> <span class="o" style="font-weight: 600;">==</span> <span class="mi" style="color: #099;">0</span><span class="p">)</span> <span class="p">{</span></span>
</pre>
</td>
</tr>

</table>
<div style="">
<p dir="auto">If by 'error out' you mean <code>goto cleanup</code>, I don't think that is safe.  That would break the fallthrough behavior to process openssl encrypted private keys if pkcs8 processing fails.  However, your point about an unnecessary call to <code>gnutls_x509_privkey_import_pkcs8</code> when the pin callback fails is valid.  Further, this pattern of overwriting <code>password</code> with <code>pin</code> when processing a pin is also probably wrong.  If the pin obtain when processing a pkcs8 payload fails to decrypt the payload, the original password supplied will never be used in the openssl fallthrough section.</p>
<p dir="auto">I've re-worked the pkcs8 section and the new openssl section I added to remove the unnecessary call when the pin callback fails and to also use the pin obtained directly (instead of overwriting the <code>password</code> variable).</p>
</div>


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

<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/merge_requests/1459#note_649760962">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/5f1d848b6196f554f7621a88cb278c2d/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/1459#note_649760962"}}</script>


</p>
</div>
</body>
</html>