This commit is contained in:
TheDoubleH 2022-02-11 17:30:04 +00:00
parent de09820554
commit e4f08bf9a7
187 changed files with 6620 additions and 6342 deletions

View file

@ -5,16 +5,16 @@
<meta name=generator content="Hugo 0.92.1">
<meta name=description content>
<title>Data Encryption :: AL Guidelines</title>
<link href=/css/nucleus.css?1644506469 rel=stylesheet>
<link href=/css/fontawesome-all.min.css?1644506469 rel=stylesheet>
<link href=/css/featherlight.min.css?1644506469 rel=stylesheet>
<link href=/css/perfect-scrollbar.min.css?1644506469 rel=stylesheet>
<link href=/css/auto-complete.css?1644506469 rel=stylesheet>
<link href=/css/theme.css?1644506469 rel=stylesheet>
<link href=/css/theme-blue.css?1644506469 rel=stylesheet>
<link href=/css/variant.css?1644506469 rel=stylesheet>
<link href=/css/print.css?1644506469 rel=stylesheet media=print>
<script src=/js/jquery.min.js?1644506469></script>
<link href=/css/nucleus.css?1644600599 rel=stylesheet>
<link href=/css/fontawesome-all.min.css?1644600599 rel=stylesheet>
<link href=/css/featherlight.min.css?1644600599 rel=stylesheet>
<link href=/css/perfect-scrollbar.min.css?1644600599 rel=stylesheet>
<link href=/css/auto-complete.css?1644600599 rel=stylesheet>
<link href=/css/theme.css?1644600599 rel=stylesheet>
<link href=/css/theme-blue.css?1644600599 rel=stylesheet>
<link href=/css/variant.css?1644600599 rel=stylesheet>
<link href=/css/print.css?1644600599 rel=stylesheet media=print>
<script src=/js/jquery.min.js?1644600599></script>
<style>:root #header+#content>#left>#rlblock_left{display:none!important}</style>
</head>
<body data-url=/navpatterns/1-patterns/security/2-data-encryption/>
@ -32,9 +32,9 @@ ALGuidelines.Dev
<input data-search-input id=search-by type=search placeholder=Search...>
<span data-search-clear><i class="fas fa-times"></i></span>
</div>
<script src=/js/lunr.min.js?1644506469></script>
<script src=/js/auto-complete.js?1644506469></script>
<script src=/js/search.js?1644506469></script>
<script src=/js/lunr.min.js?1644600599></script>
<script src=/js/auto-complete.js?1644600599></script>
<script src=/js/search.js?1644600599></script>
</div>
<div class=highlightable>
<ul class=topics>
@ -256,61 +256,86 @@ ALGuidelines.Dev
<main id=body-inner>
<h1>Data Encryption</h1>
<p><em>By Bogdana Botez at Microsoft Development Center Copenhagen</em></p>
<p>__</p>
<p>_<a href=Logo-_2D00_-Encryption.png><img src=Logo-_2D00_-Encryption.png alt=" "></a><br>
_</p>
<hr>
<p><strong>Context</strong>: After applying <a href=/nav/w/designpatterns/275.1-sensitive-data-encapsulation><strong>Sensitive Data Encapsulation</strong></a>, all sensitive data is gathered in a known place in the database. This makes it possible to apply further protection best practices.</p>
<p><a href=Logo-_2D00_-Encryption.png><img src=Logo-_2D00_-Encryption.png alt=" "></a></p>
<p><strong>Context</strong>: After applying <a href=/navpatterns/1-patterns/security/1-sensitive-data-encapsulation/><strong>Sensitive Data Encapsulation</strong></a>, all sensitive data is gathered in a known place in the database. This makes it possible to apply further protection best practices.</p>
<p><strong>Problem</strong>: If any non-authorized actor manages to get access to a copy of the database, the sensitive data is immediately available in clear-text.</p>
<p>**<br>
**</p>
<p><strong>Forces:</strong></p>
<ul>
<li><strong>Accessibility:</strong> anyone who managed to steal a copy of the database can at once read the sensitive information.</li>
</ul>
<p><strong>Solution:</strong> Encrypt sensitive data. Dynamics NAV offers a simple mechanism for data encryption, to be used by NAV developers.</p>
<p>Figure 1 adds one more step (in continuation of the figure in pattern <strong><a href=/nav/w/designpatterns/275.sensitive-data-encapsulation>Sensitive Data Encapsulation</a></strong>), in which the first two panels describe how sensitive data has all been gathered in one known place. This makes the current pattern, <strong>Encryption</strong>, much easier &ndash; since now data needs to be encrypted in only one place. The last panel of Figure 1 shows the system after the next step, <strong>Encryption</strong>, has been implemented. This shows the iterative process of applying patterns and making the code better step by step.</p>
<p>Figure 1 adds one more step (in continuation of the figure in pattern <strong><a href=/navpatterns/1-patterns/security/1-sensitive-data-encapsulation/>Sensitive Data Encapsulation</a></strong>), in which the first two panels describe how sensitive data has all been gathered in one known place. This makes the current pattern, <strong>Encryption</strong>, much easier &ndash; since now data needs to be encrypted in only one place. The last panel of Figure 1 shows the system after the next step, <strong>Encryption</strong>, has been implemented. This shows the iterative process of applying patterns and making the code better step by step.</p>
<p><a href=Multi-_2D00_-1-2-3.JPG><img src=Multi-_2D00_-1-2-3.JPG alt=" "></a></p>
<p><em>Figure 1- <strong>Encryption</strong> becomes easier after first applying <a href=/nav/w/designpatterns/275.1-sensitive-data-encapsulation><strong>Sensitive Data Encapsulation</strong></a>.</em></p>
<hr>
<p><em>Figure 1- <strong>Encryption</strong> becomes easier after first applying <a href=/navpatterns/1-patterns/security/1-sensitive-data-encapsulation/><strong>Sensitive Data Encapsulation</strong></a>.</em></p>
<p><strong>Usage</strong>: in Dynamics NAV, codeunit 1266 Encryption Management offers an API for encryption of data. The available functionality is described in Table 1.</p>
<p>Table 1- Encryption functionality in Dynamics NAV (found in codeunit 1266 Encryption Management)</p>
<p><strong>Procedure</strong></p>
<p><strong>Description</strong></p>
<p><strong>EnableEncryption</strong></p>
<p>Confirms with the user before enabling encryption in all companies of the current database.</p>
<p><strong>EnableEncryptionSilently</strong></p>
<p>Enables encryption without UI interaction (to be used for web services).</p>
<p><strong>DisableEncryption</strong></p>
<p>Disables encryption. Has a boolean &ldquo;Silent&rdquo; parameter which enables/disables UI interaction.</p>
<p><strong>Encrypt</strong></p>
<p>Checks that encryption is possible before encrypting the given text.</p>
<p><strong>Decrypt</strong></p>
<p>Checks that encryption is possible before decrypting the given text.</p>
<p><strong>ExportKey</strong></p>
<p>If encryption is possible, it shows a confirmation dialog to confirm the export of the encryption key, and proceeds to saving it to a location chosen by the user.</p>
<p><strong>ImportKey</strong></p>
<p>Imports the encryption key from a user chosen location.</p>
<p><strong>ChangeKey</strong></p>
<p>Changes the encryption key.</p>
<p><strong>IsEncryptionEnabled</strong></p>
<p>Returns TRUE is encryption is enabled.</p>
<p><strong>IsEncryptionPossible</strong></p>
<p>Check is the correct key is present, which only works if encryption is enabled.</p>
<p><strong>DeleteEncryptedDataInAllCompanies</strong></p>
<p>Confirms through UI and if the user agrees, deletes all data stored in the Service Password table for all companies in the current database. At the end, it deletes the encryption key.</p>
<table>
<thead>
<tr>
<th>Procedure</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>EnableEncryption</td>
<td>Confirms with the user before enabling encryption in all companies of the current database.</td>
</tr>
<tr>
<td>EnableEncryptionSilently</td>
<td>Enables encryption without UI interaction (to be used for web services).</td>
</tr>
<tr>
<td>DisableEncryption</td>
<td>Disables encryption. Has a boolean &ldquo;Silent&rdquo; parameter which enables/disables UI interaction.</td>
</tr>
<tr>
<td>Encrypt</td>
<td>Checks that encryption is possible before encrypting the given text.</td>
</tr>
<tr>
<td>Decrypt</td>
<td>Checks that encryption is possible before decrypting the given text.</td>
</tr>
<tr>
<td>ExportKey</td>
<td>If encryption is possible, it shows a confirmation dialog to confirm the export of the encryption key, and proceeds to saving it to a location chosen by the user.</td>
</tr>
<tr>
<td>ImportKey</td>
<td>Imports the encryption key from a user chosen location.</td>
</tr>
<tr>
<td>ChangeKey</td>
<td>Changes the encryption key.</td>
</tr>
<tr>
<td>IsEncryptionEnabled</td>
<td>Returns TRUE is encryption is enabled.</td>
</tr>
<tr>
<td>IsEncryptionPossible</td>
<td>Check is the correct key is present, which only works if encryption is enabled.</td>
</tr>
<tr>
<td>DeleteEncryptedDataInAllCompanies</td>
<td>Confirms through UI and if the user agrees, deletes all data stored in the Service Password table for all companies in the current database. At the end, it deletes the encryption key.</td>
</tr>
</tbody>
</table>
<p><strong>User confirmation of encryption</strong></p>
<p>Ideally, encryption should be enabled by default.</p>
<p>However, in some versions of Dynamics NAV, there are places where any user who happens to hit a sensitive field (like a password) is asked if they want to encrypt or not. If user confirmation is needed, then let only the security administrators decide (not any random user).</p>
<p>To ask the security administrator if they want to enable encryption, plug the code below into the OnValidate trigger of the data field which is to be encrypted. This trigger will then get executed each time there&rsquo;s a change on the password field. For example, if the user is entering a password, then add a call to this procedure to Password &ndash; OnValidate() trigger:</p>
<p>EncryptionIsNotActivatedQst@1001 : TextConst &lsquo;ENU=Data encryption is not activated. It is recommended that you encrypt data. \Do you want to open the Data Encryption Management window?';</p>
<p>LOCAL PROCEDURE CheckEncryption@6();</p>
<p>BEGIN</p>
<p>IF NOT ENCRYPTIONENABLED THEN</p>
<p>IF CONFIRM(EncryptionIsNotActivatedQst) THEN</p>
<p>PAGE.RUN(PAGE::&ldquo;Data Encryption Management&rdquo;);</p>
<p>END;</p>
<p>The code above will guide the user on encrypting, storing the encryption key and choosing a safe password, as follows. Consider for example that NAV is used by a small business, where Stan is the business owner. Hence, Stan has access to all NAV setup and security decisions. Stan wants to enable a connection between NAV and CRM. In NAV, he opens page CRM Connection Setup and enters the URL, user name and password for CRM (Figure 10). When Stan leaves the password field, if data encryption is not enabled, then he sees the confirmation message in Figure 2.</p>
<div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-al data-lang=al>EncryptionIsNotActivatedQst@<span style=color:#ae81ff>1001</span> : <span style=color:#66d9ef>TextConst</span> <span style=color:#e6db74>&#39;ENU=Data encryption is not activated. It is recommended that you encrypt data. \\Do you want to open the Data Encryption Management window?&#39;</span>;
<span style=color:#66d9ef>LOCAL</span> <span style=color:#66d9ef>PROCEDURE</span> CheckEncryption@<span style=color:#ae81ff>6</span><span style=color:#f92672>()</span>;
<span style=color:#66d9ef>BEGIN</span>
<span style=color:#66d9ef>IF</span> <span style=color:#f92672>NOT</span> ENCRYPTIONENABLED <span style=color:#66d9ef>THEN</span>
<span style=color:#66d9ef>IF</span> CONFIRM<span style=color:#f92672>(</span>EncryptionIsNotActivatedQst<span style=color:#f92672>) </span><span style=color:#66d9ef>THEN</span>
<span style=color:#66d9ef>PAGE</span><span style=color:#f92672>.</span>RUN<span style=color:#f92672>(</span><span style=color:#66d9ef>PAGE</span>::&#34;Data Encryption Management&#34;<span style=color:#f92672>)</span>;
<span style=color:#66d9ef>END</span>;
</code></pre></div><p>The code above will guide the user on encrypting, storing the encryption key and choosing a safe password, as follows. Consider for example that NAV is used by a small business, where Stan is the business owner. Hence, Stan has access to all NAV setup and security decisions. Stan wants to enable a connection between NAV and CRM. In NAV, he opens page CRM Connection Setup and enters the URL, user name and password for CRM (Figure 10). When Stan leaves the password field, if data encryption is not enabled, then he sees the confirmation message in Figure 2.</p>
<p><a href=Encryption-_2D00_-1.JPG><img src=Encryption-_2D00_-1.JPG alt=" "></a></p>
<p><em>Figure 2- The administrator is advised to enable encryption.</em></p>
<p>Now Stan becomes aware that there is no encryption and has the opportunity to enable it. If he clicks on &ldquo;Yes&rdquo;, Stan will be taken to the Data Encryption Management page (Figure 3).</p>
@ -340,34 +365,22 @@ _</p>
<p><strong>Anti-patterns:</strong></p>
<ul>
<li><strong>Performance:</strong> Do not encrypt everything, because it will have a performance impact on the system. Only important information should be encrypted.</li>
<li><strong>System calls and &ldquo;Do It Yourself&rdquo; solutions</strong>: Although system calls for encryptions are available in NAV (ENCRYPT, DECRYPT and &lt;action>ENCRYPTIONKEY), unless there is no other way, refrain from using them directly. Use instead he API in codeunit 1266 Encryption Management, which is safer to use, because it protects against common mistakes (like attempting to encrypt an already encrypted string, enabling encryption in only one company which makes data not usable in another on the same tenant etc.). Use the <a href=/nav/w/designpatterns/277.3-single-point-of-acces><strong>Single Point of Access</strong></a> pattern to handle sensitive data which needs to be encrypted.</li>
<li><strong>System calls and &ldquo;Do It Yourself&rdquo; solutions</strong>: Although system calls for encryptions are available in NAV (ENCRYPT, DECRYPT and &lt;action>ENCRYPTIONKEY), unless there is no other way, refrain from using them directly. Use instead he API in codeunit 1266 Encryption Management, which is safer to use, because it protects against common mistakes (like attempting to encrypt an already encrypted string, enabling encryption in only one company which makes data not usable in another on the same tenant etc.). Use the <a href=/navpatterns/1-patterns/security/3-single-point-of-access/><strong>Single Point of Access</strong></a> pattern to handle sensitive data which needs to be encrypted.</li>
<li><strong>System-level encryption.</strong> The similar codeunit API 1803 Encrypted Key/Value Management is not intended to be reused by partner NAV developers. Normal NAV users do not have permission to access this resource. This stores sensitive data to be accessed by system NAV functionality.</li>
</ul>
<p><strong>References</strong></p>
<p>[1]</p>
<p>&ldquo;Wikipedia,&rdquo; [Online]. Available: <a href=https://en.wikipedia.org/wiki/Separation>https://en.wikipedia.org/wiki/Separation</a>_of_concerns.</p>
<p>[2]</p>
<p>&ldquo;GUID Structure,&rdquo; [Online]. Available: <a href=https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx>https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx</a>.</p>
<p>[3]</p>
<p>&ldquo;Wikipedia,&rdquo; [Online]. Available: <a href=https://en.wikipedia.org/wiki/Binary>https://en.wikipedia.org/wiki/Binary</a>_large_object.</p>
<p>[4]</p>
<p>waldo, &ldquo;How Do I: Manage Companies in Microsoft Dynamics NAV 2013 R2&rdquo;.</p>
<p>[5]</p>
<p>Microsoft, &ldquo;Multitenant Deployment Architecture,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx</a>.</p>
<p>[6]</p>
<p>B. Botez, &ldquo;Setup Table design pattern,&rdquo; Microsoft, 2013. [Online]. Available: <a href=https://community.dynamics.com/nav/w/designpatterns/76.setup-table>https://community.dynamics.com/nav/w/designpatterns/76.setup-table</a>. [Accessed 31 07 2016].</p>
<p>[7]</p>
<p>&ldquo;Shotgun Surgery,&rdquo; [Online]. Available: <a href=https://en.wikipedia.org/wiki/Shotgun>https://en.wikipedia.org/wiki/Shotgun</a>_surgery. [Accessed 31 07 2016].</p>
<p>[8]</p>
<p>M. Fowler, Refactoring: Improving the design of existing code, Addison Wesley, 1999.</p>
<p>[9]</p>
<p>&ldquo;Masking out,&rdquo; [Online]. Available: <a href=https://en.wikipedia.org/wiki/Data>https://en.wikipedia.org/wiki/Data</a>_masking#Masking_out. [Accessed 29 7 2016].</p>
<p>[10]</p>
<p>&ldquo;Key Vault,&rdquo; Microsoft, [Online]. Available: <a href=https://azure.microsoft.com/en-us/services/key-vault/>https://azure.microsoft.com/en-us/services/key-vault/</a>.</p>
<p>[11]</p>
<p>&ldquo;How to: Configure SSL to Secure the Connection to Microsoft Dynamics NAV Web Client,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx</a>. [Accessed 2 8 2016].</p>
<p>[12]</p>
<p>&ldquo;sniffer,&rdquo; [Online]. Available: <a href=http://compnetworking.about.com/od/networksecurityprivacy/g/bldef>http://compnetworking.about.com/od/networksecurityprivacy/g/bldef</a>_sniffer.htm. [Accessed 02 08 2016].</p>
<p>[1] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href=https://en.wikipedia.org/wiki/Separation_of_concerns>https://en.wikipedia.org/wiki/Separation_of_concerns</a>.</p>
<p>[2] &ldquo;GUID Structure,&rdquo; [Online]. Available: <a href=https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx>https://msdn.microsoft.com/en-us/library/aa373931(VS.85).aspx</a>.</p>
<p>[3] &ldquo;Wikipedia,&rdquo; [Online]. Available: <a href=https://en.wikipedia.org/wiki/Binary_large_object>https://en.wikipedia.org/wiki/Binary_large_object</a>.</p>
<p>[4] waldo, &ldquo;How Do I: Manage Companies in Microsoft Dynamics NAV 2013 R2&rdquo;.</p>
<p>[5] Microsoft, &ldquo;Multitenant Deployment Architecture,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/dn271675(v=nav.90).aspx</a>.</p>
<p>[6] B. Botez, &ldquo;Setup Table design pattern,&rdquo; Microsoft, 2013. [Online]. Available: <a href=https://community.dynamics.com/nav/w/designpatterns/76.setup-table>https://community.dynamics.com/nav/w/designpatterns/76.setup-table</a>. [Accessed 31 07 2016].</p>
<p>[7] &ldquo;Shotgun Surgery,&rdquo; [Online]. Available: <a href=https://en.wikipedia.org/wiki/Shotgun_surgery>https://en.wikipedia.org/wiki/Shotgun_surgery</a>. [Accessed 31 07 2016].</p>
<p>[8] M. Fowler, Refactoring: Improving the design of existing code, Addison Wesley, 1999.</p>
<p>[9] &ldquo;Masking out,&rdquo; [Online]. Available: <a href=https://en.wikipedia.org/wiki/Data_masking#Masking_out>https://en.wikipedia.org/wiki/Data_masking#Masking_out</a>. [Accessed 29 7 2016].</p>
<p>[10] &ldquo;Key Vault,&rdquo; Microsoft, [Online]. Available: <a href=https://azure.microsoft.com/en-us/services/key-vault/>https://azure.microsoft.com/en-us/services/key-vault/</a>.</p>
<p>[11] &ldquo;How to: Configure SSL to Secure the Connection to Microsoft Dynamics NAV Web Client,&rdquo; Microsoft, [Online]. Available: <a href="https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx">https://msdn.microsoft.com/en-us/library/hh167264(v=nav.90).aspx</a>. [Accessed 2 8 2016].</p>
<p>[12] &ldquo;sniffer,&rdquo; [Online]. Available: <a href=http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm>http://compnetworking.about.com/od/networksecurityprivacy/g/bldef_sniffer.htm</a>. [Accessed 02 08 2016].</p>
<footer class=footline>
</footer>
</main>
@ -380,12 +393,12 @@ _</p>
<div style=left:-1000px;overflow:scroll;position:absolute;top:-1000px;border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px>
<div style=border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px></div>
</div>
<script src=/js/clipboard.min.js?1644506469></script>
<script src=/js/perfect-scrollbar.min.js?1644506469></script>
<script src=/js/perfect-scrollbar.jquery.min.js?1644506469></script>
<script src=/js/jquery.svg.pan.zoom.js?1644506469></script>
<script src=/js/featherlight.min.js?1644506469></script>
<script src=/js/modernizr.custom-3.6.0.js?1644506469></script>
<script src=/js/relearn.js?1644506469></script>
<script src=/js/clipboard.min.js?1644600600></script>
<script src=/js/perfect-scrollbar.min.js?1644600600></script>
<script src=/js/perfect-scrollbar.jquery.min.js?1644600600></script>
<script src=/js/jquery.svg.pan.zoom.js?1644600600></script>
<script src=/js/featherlight.min.js?1644600600></script>
<script src=/js/modernizr.custom-3.6.0.js?1644600600></script>
<script src=/js/relearn.js?1644600600></script>
</body>
</html>