<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style='--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;'>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>
GitLab
</title>
<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>
<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style='font-size: inherit; -webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";'>
<div class="content">
<p class="details" style="font-style: italic; color: #626168;">
<a href="https://gitlab.com/aberaud">Adrien Béraud</a> created an issue: <a href="https://gitlab.com/gnutls/gnutls/-/issues/1734">#1734</a>
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<h2 dir="auto" style="margin-top: 0; margin-bottom: 10px;" align="initial">
<a href="#description-of-problem" aria-hidden="true" class="anchor" id="user-content-description-of-problem" style="margin-top: 0; margin-left: -20px; text-decoration: none; outline: none; position: absolute; width: 20px;"></a>Description of problem:</h2>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">We are transitioning from RSA PKCSv1.5 to OAEP encryption, and are currently facing a possible limitation in the GnuTLS API.
To my knowledge, OAEP is an encryption padding scheme which doesn't prevent or forbid the use of an RSA private key for signing.</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">However, using the latest version of GnuTLS, I've been unable to perform signing operation using RSA private keys with OAEP information.</p>
<h2 dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">
<a href="#version-of-gnutls-used" aria-hidden="true" class="anchor" id="user-content-version-of-gnutls-used" style="margin-top: 0; margin-left: -20px; text-decoration: none; outline: none; position: absolute; width: 20px;"></a>Version of gnutls used:</h2>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Any version since 3.8.4.</p>
<h2 dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">
<a href="#how-reproducible" aria-hidden="true" class="anchor" id="user-content-how-reproducible" style="margin-top: 0; margin-left: -20px; text-decoration: none; outline: none; position: absolute; width: 20px;"></a>How reproducible:</h2>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre data-canonical-lang="c" class="code highlight js-syntax-highlight language-c" v-pre="true" style='display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 1rem; padding: 12px; border: 1px solid #dcdcde;'><code style='font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; border-radius: .25rem; background-color: inherit; white-space: pre; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;'><span id="LC1" class="line" lang="c" style="margin-top: 0;"><span class="n" style="margin-top: 0;">gnutls_x509_privkey_t</span> <span class="n">key</span><span class="p">;</span></span>
<span id="LC2" class="line" lang="c"><span class="n" style="margin-top: 0;">gnutls_x509_privkey_init</span><span class="p">(</span><span class="o">&</span><span class="n">key</span><span class="p">);</span></span>
<span id="LC3" class="line" lang="c"><span class="n" style="margin-top: 0;">gnutls_x509_privkey_generate</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">GNUTLS_PK_RSA</span><span class="p">,</span> <span class="mi">4096</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span></span>
<span id="LC4" class="line" lang="c"></span>
<span id="LC5" class="line" lang="c"><span class="n" style="margin-top: 0;">gnutls_x509_spki_t</span> <span class="n">spki</span><span class="p">;</span></span>
<span id="LC6" class="line" lang="c"><span class="n" style="margin-top: 0;">gnutls_x509_spki_init</span><span class="p">(</span><span class="o">&</span><span class="n">spki</span><span class="p">);</span></span>
<span id="LC7" class="line" lang="c"><span class="n" style="margin-top: 0;">gnutls_x509_spki_set_rsa_oaep_params</span><span class="p">(</span><span class="n">spki</span><span class="p">,</span> <span class="n">GNUTLS_DIG_SHA512</span><span class="p">,</span> <span class="n">nullptr</span><span class="p">);</span></span>
<span id="LC8" class="line" lang="c"><span class="n" style="margin-top: 0;">gnutls_x509_privkey_set_spki</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">spki</span><span class="p">,</span> <span class="mi">0</span><span class="p">);</span></span>
<span id="LC9" class="line" lang="c"><span class="n" style="margin-top: 0;">gnutls_x509_spki_deinit</span><span class="p">(</span><span class="n">spki</span><span class="p">);</span></span>
<span id="LC10" class="line" lang="c"></span>
<span id="LC11" class="line" lang="c"><span class="n" style="margin-top: 0;">gnutls_datum_t</span> <span class="n">dat</span> <span class="o">=</span> <span class="p">{</span> <span class="p">(</span><span class="kt">unsigned</span> <span class="kt">char</span> <span class="o">*</span><span class="p">)</span><span class="s">"Hello, World!"</span><span class="p">,</span> <span class="mi">13</span> <span class="p">};</span></span>
<span id="LC12" class="line" lang="c"><span class="kt" style="margin-top: 0;">uint8_t</span> <span class="n">sig</span><span class="p">[</span><span class="mi">4096</span><span class="o">/</span><span class="mi">8</span><span class="p">];</span></span>
<span id="LC13" class="line" lang="c"><span class="kt" style="margin-top: 0;">size_t</span> <span class="n">sig_size</span> <span class="o">=</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">sig</span><span class="p">);</span></span>
<span id="LC14" class="line" lang="c"><span class="kt" style="margin-top: 0;">int</span> <span class="n">err</span> <span class="o">=</span> <span class="n">gnutls_x509_privkey_sign_data</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">GNUTLS_DIG_SHA512</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">&</span><span class="n">dat</span><span class="p">,</span> <span class="n">sig</span><span class="p">,</span> <span class="o">&</span><span class="n">sig_size</span><span class="p">);</span></span>
<span id="LC15" class="line" lang="c"><span class="n" style="margin-top: 0;">printf</span><span class="p">(</span><span class="s">"gnutls_x509_privkey_sign_data returned %d: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">err</span><span class="p">,</span> <span class="n">gnutls_strerror</span><span class="p">(</span><span class="n">err</span><span class="p">));</span></span>
<span id="LC16" class="line" lang="c"><span class="n" style="margin-top: 0;">gnutls_x509_privkey_deinit</span><span class="p">(</span><span class="n">key</span><span class="p">);</span></span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
<h2 dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">
<a href="#actual-results" aria-hidden="true" class="anchor" id="user-content-actual-results" style="margin-top: 0; margin-left: -20px; text-decoration: none; outline: none; position: absolute; width: 20px;"></a>Actual results:</h2>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">This fails with <code style='font-size: 90%; color: #18171d; word-wrap: break-word; border-radius: .25rem; background-color: #ececef; margin-top: 0; font-weight: inherit; white-space: break-spaces; overflow-wrap: break-word; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;'>-50 The request is invalid</code>.
Using the abstract API gives the same result.</p>
<h2 dir="auto" style="margin-top: 20px; margin-bottom: 10px;" align="initial">
<a href="#expected-results" aria-hidden="true" class="anchor" id="user-content-expected-results" style="margin-top: 0; margin-left: -20px; text-decoration: none; outline: none; position: absolute; width: 20px;"></a>Expected results:</h2>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">It would be useful to be able to use OAEP keys for signing.</p>
<p dir="auto" style="color: #3a383f; margin: 0;" align="initial">The GnuTLS doesn't seem to provide any easy way to circumvent this, as it doesn't allow to build an spki of type GNUTLS_PK_RSA to set on the private key, and doesn't provide an API to remove spki information form a private key. The only way would seem to export and import raw key parameters, which doesn't feel proper.</p>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">
—
<br>
Reply to this email directly or <a href="https://gitlab.com/gnutls/gnutls/-/issues/1734">view it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.com">gitlab.com</a>. <a href="https://gitlab.com/-/sent_notifications/1-amp2r857zf9hn6s7gnial0we2/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.com/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.com/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.com/gnutls/gnutls/-/issues/1734 at 1757394684
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.com/gnutls/gnutls/-/issues/1734"}}</script>
</p>
</div>
</body>
</html>