<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[UniAuth Blog]]></title><description><![CDATA[UniAuth Blog]]></description><link>https://blog.uniauth.com</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1700987221131/lNHu3xYva.png</url><title>UniAuth Blog</title><link>https://blog.uniauth.com</link></image><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 10:33:15 GMT</lastBuildDate><atom:link href="https://blog.uniauth.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[[Secure 101] What is Penetration Testing (pen testing)? How It Conducted?]]></title><description><![CDATA[Penetration Testing (or pen testing) is a mechanism used to verify whether network defenses are functioning as expected. This test simulates the behavior of hackers and malicious users attempting to breach a company’s website, information systems, or...]]></description><link>https://blog.uniauth.com/what-is-pen-testing-how-it-conducted</link><guid isPermaLink="true">https://blog.uniauth.com/what-is-pen-testing-how-it-conducted</guid><category><![CDATA[pentesting]]></category><category><![CDATA[Pentest]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Simon Asika]]></dc:creator><pubDate>Mon, 26 Aug 2024 12:37:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1724675801144/cbdb84a4-500e-4deb-803f-a22004fbf879.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Penetration Testing (or pen testing)</strong> is a mechanism used to verify whether network defenses are functioning as expected. This test simulates the behavior of hackers and malicious users attempting to breach a company’s website, information systems, or devices, and analyzes the target's risk level to assess whether security measures need enhancement. The ultimate goal is to identify and rectify security vulnerabilities before a real attack occurs.</p>
<h2 id="heading-differences-between-vulnerabilitysource-code-scanning-and-penetration-testing">Differences between Vulnerability/Source Code Scanning and Penetration Testing</h2>
<p>Vulnerability and source code scanning are performed by automated scanning software. They are cost-effective and quick to execute but can only detect existing vulnerabilities, such as security issues in programming syntax.</p>
<p>Penetration testing, on the other hand, simulates hacker attacks through a combination of tactics to verify whether defenses can be breached. It is more costly but can detect the latest security vulnerabilities in real-time and provide recommendations for remediation. Therefore, penetration testing is more expensive and requires longer preparation.</p>
<h2 id="heading-types-of-penetration-testing">Types of Penetration Testing</h2>
<p>The following types are provided by <a target="_blank" href="https://www.cloudflare.com/learning/security/glossary/what-is-penetration-testing/">Cloudflare</a>:</p>
<ul>
<li><p><strong>Open-box Pen Test</strong>: In an open test, hackers will be given some information about the target company’s security in advance.</p>
</li>
<li><p><strong>Closed-box Pen Test</strong>: Also known as a "single-blind" test, in this scenario, hackers receive no background information other than the target company’s name.</p>
</li>
<li><p><strong>Covert Pen Test</strong>: Also called a "double-blind" penetration test, in this situation, almost no one in the company is aware that a penetration test is being conducted, including IT and security professionals who would respond to an attack. In covert tests, hackers must clearly define the scope and other details of the test in writing beforehand to avoid legal issues.</p>
</li>
<li><p><strong>External Pen Test</strong>: In an external test, ethical hackers attempt to breach the company’s external technology, such as its website and external network servers. In some cases, hackers may not even enter the company’s building. This could mean they conduct attacks remotely or from a truck or van parked nearby.</p>
</li>
<li><p><strong>Internal Pen Test</strong>: In an internal test, ethical hackers perform tests from within the company’s internal network. This type of test can determine how much damage a disgruntled employee might cause from behind the company firewall.</p>
</li>
</ul>
<h2 id="heading-preparation-before-pen-testing">Preparation Before Pen Testing</h2>
<p>Before conducting penetration testing, it’s common to perform a "vulnerability scan" or "source code scan" and preemptively fix visible vulnerabilities before conducting a simulated penetration to verify if these known vulnerabilities can be exploited for an intrusion.</p>
<p>Additionally, since penetration testing is a form of "vulnerability probing" and involves intrusion into company property, unauthorized penetration testing may be illegal in many countries. Therefore, it is crucial to agree on the test targets (website or host) with the vendor and sign a contract and consent form to avoid legal disputes.</p>
<h2 id="heading-pen-testing-process">Pen Testing Process</h2>
<p>The process of penetration testing includes:</p>
<ol>
<li><p><strong>Project Requirements Confirmation</strong>: Confirm the testing requirements and sign legal authorization, an essential step to ensure the tester's actions are legal.</p>
</li>
<li><p><strong>Preparation Phase</strong>: Confirm the testing methods, scope, and time, and gather publicly available information about the target.</p>
</li>
<li><p><strong>Information Gathering</strong>: Develop strategies, gather data, and analyze information according to the <a target="_blank" href="https://www.isecom.org/OSSTMM.3.pdf">OSSYMM</a> framework.</p>
</li>
<li><p><strong>Data Analysis and Vulnerability Scanning</strong>: Use OWASP standards to perform risk scanning, pre-emptively eliminating known issues.</p>
</li>
<li><p><strong>Target Penetration</strong>: Execute actual penetration actions to attempt to breach the system.</p>
</li>
<li><p><strong>Vulnerability Reporting</strong>: After testing, write a report detailing various vulnerabilities and remediation recommendations.</p>
</li>
</ol>
<p>After obtaining the report, the operations team will follow the report’s content to patch the system. Finally, according to the contract, discussions may be held to determine whether retesting is necessary.</p>
<h2 id="heading-standard-items-in-pen-testing">Standard Items in Pen Testing</h2>
<p>Currently, there is no unified mandatory standard for penetration testing, but tests are usually conducted following public security testing items like OWASP Top 10. Here, we provide three mainstream testing standards: OWASP, OSSTMM, and SANS.</p>
<h3 id="heading-owasp-top-10"><strong>OWASP Top 10</strong></h3>
<p>The Open Web Application Security Project (OWASP) is an international non-profit organization dedicated to web application security. All of their materials are freely available and easily accessible on their website, enabling anyone to improve their web application security.</p>
<p>The OWASP Top 10 is one of the most widely adopted security checklists globally, with the latest version being <a target="_blank" href="https://owasp.org/Top10/">OWASP Top 10 2021</a>.</p>
<ul>
<li><p><strong>A01:2021 - Broken Access Control</strong></p>
</li>
<li><p><strong>A02:2021 - Cryptographic Failures</strong></p>
</li>
<li><p><strong>A03:2021 - Injection</strong></p>
</li>
<li><p><strong>A04:2021 - Insecure Design</strong></p>
</li>
<li><p><strong>A05:2021 - Security Misconfiguration</strong></p>
</li>
<li><p><strong>A06:2021 - Vulnerable and Outdated Components</strong></p>
</li>
<li><p><strong>A07:2021 - Identification and Authentication Failures</strong></p>
</li>
<li><p><strong>A08:2021 - Software and Data Integrity Failures</strong></p>
</li>
<li><p><strong>A09:2021 - Security Logging and Monitoring Failures</strong></p>
</li>
<li><p><strong>A10:2021 - Server-Side Request Forgery (SSRF)</strong></p>
</li>
</ul>
<h3 id="heading-osstmm"><strong>OSSTMM</strong></h3>
<p>The <a target="_blank" href="https://www.isecom.org/research.html">Open Source Security Testing Methodology Manual (OSSTMM)</a> is a comprehensive framework covering areas such as vulnerability scanning, penetration testing, and social engineering. Below are the items listed under the Information Security Testing category:</p>
<ul>
<li><p><strong>Footprinting</strong>: Identify and gather publicly available information about the target system or network.</p>
</li>
<li><p><strong>Scanning</strong>: Use tools and techniques to identify open ports, services, and vulnerabilities in the target system.</p>
</li>
<li><p><strong>Enumeration</strong>: Obtain detailed information about the internal structure of the target system or network, such as usernames, system names, and shared resources.</p>
</li>
<li><p><strong>Vulnerability Assessment</strong>: Analyze known vulnerabilities in the system and assess their potential impact.</p>
</li>
<li><p><strong>Exploitation</strong>: Attempt to exploit identified vulnerabilities to gain unauthorized access to the system.</p>
</li>
<li><p><strong>Post-Exploitation</strong>: After gaining system access, further explore and exploit other system resources or data.</p>
</li>
<li><p><strong>Reporting</strong>: Summarize the penetration test results, providing vulnerability descriptions and remediation recommendations.</p>
</li>
</ul>
<h3 id="heading-sans-top-20"><strong>SANS Top 20</strong></h3>
<p>The <a target="_blank" href="https://www.cm-alliance.com/consultancy/compliance-gap-analysis/sans-top-20-controls/">SANS 20 Security Controls</a>, published by the Center for Strategic and International Studies (CSIS), are prioritized mitigation measures that can help improve cybersecurity. They include a set of 20 components to help you address common attack vectors and fix potential vulnerabilities.</p>
<ul>
<li><p><strong>CSC 1: Inventory of Authorized and Unauthorized Devices</strong></p>
</li>
<li><p><strong>CSC 2: Inventory of Authorized and Unauthorized Software</strong></p>
</li>
<li><p><strong>CSC 3: Secure Configurations for Hardware and Software on Mobile Devices, Laptops, Workstations, and Servers</strong></p>
</li>
<li><p><strong>CSC 4: Continuous Vulnerability Assessment and Remediation</strong></p>
</li>
<li><p><strong>CSC 5: Controlled Use of Administrative Privileges</strong></p>
</li>
<li><p><strong>CSC 6: Maintenance, Monitoring, and Analysis of Audit Logs</strong></p>
</li>
<li><p><strong>CSC 7: Email and Web Browser Protections</strong></p>
</li>
<li><p><strong>CSC 8: Malware Defenses</strong></p>
</li>
<li><p><strong>CSC 9: Limitation and Control of Network Ports, Protocols, and Services</strong></p>
</li>
<li><p><strong>CSC 10: Data Recovery Capability</strong></p>
</li>
<li><p><strong>CSC 11: Secure Configurations for Network Devices, such as Firewalls, Routers, and Switches</strong></p>
</li>
<li><p><strong>CSC 12: Boundary Defense</strong></p>
</li>
<li><p><strong>CSC 13: Data Protection</strong></p>
</li>
<li><p><strong>CSC 14: Controlled Access Based on the Need to Know</strong></p>
</li>
<li><p><strong>CSC 15: Wireless Access Control</strong></p>
</li>
<li><p><strong>CSC 16: Account Monitoring and Control</strong></p>
</li>
<li><p><strong>CSC 17: Security Skills Assessment and Appropriate Training to Fill Gaps</strong></p>
</li>
<li><p><strong>CSC 18: Application Software Security</strong></p>
</li>
<li><p><strong>CSC 19: Incident Response and Management</strong></p>
</li>
<li><p><strong>CSC 20: Penetration Tests and Red Team Exercises</strong></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Authman - An Authy Alternative for TOTP 2FA]]></title><description><![CDATA[In the modern internet environment, a simple username and password are no longer sufficient to protect people's accounts. Major websites have started to enforce two-step verification to prevent account theft.
In recent years, people have used two-ste...]]></description><link>https://blog.uniauth.com/authman-2fa</link><guid isPermaLink="true">https://blog.uniauth.com/authman-2fa</guid><category><![CDATA[2FA]]></category><category><![CDATA[Security]]></category><category><![CDATA[authentication]]></category><dc:creator><![CDATA[Simon Asika]]></dc:creator><pubDate>Sat, 15 Jun 2024 06:14:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1718433764812/2cdbd861-4dbb-4077-9e1f-5fdc2d7bcbba.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the modern internet environment, a simple username and password are no longer sufficient to protect people's accounts. Major websites have started to enforce two-step verification to prevent account theft.</p>
<p>In recent years, people have used two-step verification apps like Google Authenticator, OneAuth, and Aegis to help them pass TOTP authentication. People who needs cross-platform synchronization will choose Twilio Authy, which can sync accounts across iOS, Android, Mac, and Windows devices, eliminating concerns about restoring accounts after losing a phone.</p>
<p>However, some users consider Authy’s lack of export functionality a major concern for data autonomy. With Authy announcing the <a target="_blank" href="https://help.twilio.com/articles/19753631228315">end of support for desktop applications</a> (Mac, Windows) in March 2024, people started looking for alternatives. Currently, there are few 2FA software options that support both mobile and desktop applications and synchronization well. This brings us to the features of the <a target="_blank" href="https://authman.simular.co/">Authman App</a> we are introducing today (Which is released by <a target="_blank" href="https://simular.co/">our team</a>).</p>
<h2 id="heading-security-is-the-top-priority">Security is the Top Priority</h2>
<p>During Authman's development, we decided to implement the strongest security mechanisms. We referenced the security mechanisms of password managers like 1Password and Bitwarden to design Authman’s encryption chain process.</p>
<p>First, all 2FA tokens are encrypted by your password (through the encryption chain), and your password is authenticated to the server using the <a target="_blank" href="https://blog.uniauth.com/what-is-secure-remote-password">Secure Remote Password (SRP) protocol</a>, which means that the password is never transmitted to the server in plain text. This ensures that no Authman staff can see your account data. Even in the worst-case scenario where Authman’s database contents are leaked, hackers would be unable to decrypt your data. For this purpose, we even create and release our own modern <a target="_blank" href="https://www.npmjs.com/package/@windwalker-io/srp">SRP library</a> and <a target="_blank" href="https://www.npmjs.com/package/bigint-toolkit">ES2020 bigint toolkit</a>.</p>
<p>Next, we chose the most advanced encryption mechanisms available today, using Argon2 for key derivation and XSalsa20 for token encryption, reducing the chances of the encryption algorithm being cracked in the near future.</p>
<p>Additionally, Authman currently does not provide device detection and management to avoid leaking personal device information. However, it offers a <a target="_blank" href="https://authman.simular.co/docs/authentication.html#sign-out-from-all-devices">global session expiration option</a>, allowing you to log out of all devices with one click to prevent further damage from a lost device. (We do plan to implement device management via encryption mechanisms in the future, but it depends on that we can ensure that the device information can be fully de-identified.)</p>
<p>Finally, we painfully decided to give-up the password reset function (at least for now) to avoid social engineering attacks exploiting the password reset process.</p>
<p>Most importantly, Authman is open source, allowing anyone to review the code and encryption mechanisms to ensure no backdoors exist.</p>
<p>These mechanisms may not be as comprehensive as those of established password management companies, but as a newly launched small personal tool app, we believe it is capable of securing your accounts. For detailed encryption principles, please refer to the <a target="_blank" href="https://authman.simular.co/faqs.html">Authman FAQ</a>.</p>
<h2 id="heading-cross-device-synchronization">Cross-Device Synchronization</h2>
<p>Authman currently uses a simple REST API for communication between the app and server. Although it cannot be used offline effectively, all devices can synchronize the current account content from the server. You only need to download and install the mobile app and desktop software to enjoy the convenient account synchronization feature.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718431708098/523ffa8b-73d7-4a12-ac25-beb9e5f7ce7d.jpeg" alt class="image--center mx-auto" /></p>
<p>To further maintain account security, both the mobile and desktop versions have a screen timeout lock feature, requiring a password to unlock. To reduce the annoyance of the unlocking process, devices supporting biometric recognition (such as mobile phones or Mac Touch ID) can enable quick unlock via biometric recognition.</p>
<p>Currently, Authman supports <a target="_blank" href="https://github.com/simular/authman-app/releases/latest">Windows</a>, <a target="_blank" href="https://github.com/simular/authman-app/releases/latest">macOS</a>, <a target="_blank" href="https://apps.apple.com/us/app/authman-2fa/id6502499482">iOS</a>, and Android, with <a target="_blank" href="https://play.google.com/store/apps/details?id=io.authman">Linux</a> support in our future plans.</p>
<h2 id="heading-customization">Customization</h2>
<p>Authman focuses not only on security but also aims to provide a pleasant user experience. All 2FA accounts can be customized.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718431814923/778e214f-0ff3-4715-a6f7-fad1e6cb648b.png" alt class="image--center mx-auto" /></p>
<p>After scanning the 2FA token, you can search for a FontAwesome icon or upload a picture to use as the account’s identification icon and change the icon color to quickly find the needed items among numerous tokens.</p>
<p>An interesting feature is that Authman supports pasting images from the clipboard. You can open a browser, search for the website’s logo, copy the image, and paste it into Authman, allowing users to create a beautifully organized account list.</p>
<h2 id="heading-data-autonomy">Data Autonomy</h2>
<p>Authman provides a complete account <a target="_blank" href="https://authman.simular.co/docs/token-managements.html#export-tokens">export and import</a> functionality (though it does not yet support scheduled automatic backups). This means you don't have to worry about vendor lock-in; you can export all your 2FA tokens at any time and easily transfer them to other applications, or use them as a manual backup mechanism.</p>
<p>Another thoughtful feature of Authman is that we know some users register 2FA tokens with a secondary phone as a manual backup. Authman allows you to <a target="_blank" href="https://authman.simular.co/docs/token-managements.html#show-backup-qrcode">display the QR code</a> for each 2FA token again, so you can immediately scan and back up each token with another phone.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718432999675/f1b4af97-7494-44ad-879e-b3686b45b45d.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-open-source-and-self-hosting">Open Source and Self-Hosting</h2>
<p>Authman is newly launched, and we have many tasks and to-do lists yet to be completed. Therefore, although we are open source, the installation documentation is not yet complete. Additionally, our team is still discussing and experimenting with how to replace necessary assets and variables like logos, titles, and API endpoints for self-hosting. Once these mechanisms are perfected, we will release detailed self-hosting documentation.</p>
<p>Of course, you can always clone the project and build it yourself if you can replace the necessary variables in the source code. And if you find any vulnerabilities or algorithm deficiencies or you want to suggest improvements, we welcome them.</p>
<p>For reporting or feature requesting, please goto GitHub <a target="_blank" href="https://github.com/simular/authman-app/discussions">Discussions</a> or <a target="_blank" href="https://github.com/simular/authman-app/issues">Issues</a>.</p>
<h2 id="heading-conclusion-make-authman-your-account-security-tool">Conclusion: Make Authman Your Account Security Tool</h2>
<p>Although Authman, as a newly launched 2FA app, it is fully capable of daily use with its core 2FA TOTP authentication code feature. More importantly, it is one of the few 2FA apps on the market that supports cross-device synchronization with desktop software and has comprehensive encryption security mechanisms, making it a trustworthy choice. So don’t wait; try <a target="_blank" href="https://authman.simular.co/">Authman</a> now.</p>
<p>See also:</p>
<ul>
<li><p><em>"Authman is a very convenient and useful solution that should be more than enough for most users."</em> - <a target="_blank" href="https://www.softpedia.com/get/Security/Authman.shtml">Softpedia</a></p>
</li>
<li><p><em>"Authman, your companion for flawless 2FA"</em> - <a target="_blank" href="https://www.justgeek.fr/authman-application-2fa-open-source-127165/">Justgeek</a></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1718431950796/6439deca-d6a7-4e94-935e-4fa8aba2deb2.jpeg" alt class="image--center mx-auto" /></p>
]]></content:encoded></item><item><title><![CDATA[Web DRM, an Overview (2) - Encrypted Media Extensions (EME)]]></title><description><![CDATA[The previous article: Web DRM, an Overview (1) - Digital Content Protection concluded that while most online resources using DRM cannot perfectly prevent users from copying content privately, there are Web DRM standards for basic video encryption pro...]]></description><link>https://blog.uniauth.com/web-drm-2-eme</link><guid isPermaLink="true">https://blog.uniauth.com/web-drm-2-eme</guid><category><![CDATA[Widevine]]></category><category><![CDATA[playready]]></category><category><![CDATA[web drm]]></category><category><![CDATA[drm]]></category><category><![CDATA[eme]]></category><dc:creator><![CDATA[Simon Asika]]></dc:creator><pubDate>Sun, 10 Dec 2023 08:29:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1702196793334/45139114-203f-41d6-8d81-63bd267f7862.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The previous article: <a target="_blank" href="https://blog.uniauth.com/web-drm-1-digital-content-protection">Web DRM, an Overview (1) - Digital Content Protection</a> concluded that while most online resources using DRM cannot perfectly prevent users from copying content privately, there are Web DRM standards for basic video encryption protection. These standards at least prevent unauthorized users from easily accessing videos.</p>
<h2 id="heading-about-eme-and-web-drm"><strong>About EME and Web DRM</strong></h2>
<p>In 2017, amidst controversy, W3C <a target="_blank" href="https://www.theverge.com/2017/7/8/15942238/web-drm-standard-eme-approved-controversy#comments">passed the Web DRM standard</a>, also known as <a target="_blank" href="https://en.wikipedia.org/wiki/Encrypted_Media_Extensions">EME (Encrypted Media Extensions)</a>. EME is essentially a universal specification for different DRM manufacturers to communicate using the same standard, with each manufacturer implementing their own encryption and decryption technologies.</p>
<p>This standard has been in existence since 2012 as an unofficial standard among browsers, existing in a closed-source CDM (Content Decryption Module) form in browsers. Therefore, W3C's passage of the EME standard merely formalized and upgraded it to an official standard, despite significant controversy and skepticism from advocates of internet openness. See: <a target="_blank" href="https://www.w3.org/blog/2017/on-eme-in-html5/">"W3C Blog: On EME in HTML5."</a></p>
<blockquote>
<p>If W3C did not recommend EME then the browser vendors would just make it outside W3C. If EME did not exist, vendors could just create new Javascript based versions. And without using the web at all, it is so easy to invite ones viewers to switching to view the content on a proprietary app. And if the closed platforms prohibited DRM in apps, then the large content providers would simply distribute their own set-top boxes and game consoles as the only way to watch their stuff.</p>
<p>— Tim Berners-Lee</p>
</blockquote>
<p>Since EME is a standard, the actual identity verification and encryption/decryption are carried out by the CDM module specified in the standard, developed by individual DRM vendors. Under the EME standard, a website or application can use the same interface or keys to handle encrypted content from different DRM vendors, as long as the encryption format of the video is determined beforehand.</p>
<p>The main popular DRM vendors under the EME standard includes Microsoft's <a target="_blank" href="https://www.microsoft.com/playready/">PlayReady</a>, Google's <a target="_blank" href="https://www.widevine.com/">Widevine</a>, and Apple's <a target="_blank" href="https://developer.apple.com/streaming/fps/">FairPlay</a>, each corresponding to different browsers:</p>
<ul>
<li><p>Chrome: Widevine</p>
</li>
<li><p>Edge, IE11: PlayReady</p>
</li>
<li><p>Firefox: Widevine</p>
</li>
<li><p>Opera: Widevine</p>
</li>
<li><p>Safari: FairPlay</p>
</li>
</ul>
<p>There is also a <a target="_blank" href="https://github.com/Dash-Industry-Forum/ClearKey-Content-Protection/blob/master/README.md">ClearKey</a> which does not depend on any vendors and it is cross-brower, you can implement it for development or testing use.</p>
<p>The advantage of using the EME standard is that you can encrypt your videos in multiple ways, and then decrypt them with the same key and program on different browsers, automatically recognizing the encryption method. CDM itself is closed-source, so hackers cannot access your decryption algorithm as they could with reverse-engineered JavaScript code. Therefore, compared to developing your own encryption/decryption mechanisms, security is further enhanced.</p>
<h2 id="heading-start-using-eme-to-protect-video-resources"><strong>Start Using EME to Protect Video Resources</strong></h2>
<p>For businesses wanting to try EME protection, the fastest way is to choose an authorized third-party service provider, such as <a target="_blank" href="https://www.ezdrm.com/">EZDRM</a>, <a target="_blank" href="https://www.axinom.com/">Axinom</a>, <a target="_blank" href="https://castlabs.com/">castLabs</a>, etc. You can find globally authorized manufacturers from the following DRM pages:</p>
<ul>
<li><p>Widevine: <a target="_blank" href="https://www.widevine.com/training#partners">Widevine Training Partners</a></p>
</li>
<li><p>PlayReady: <a target="_blank" href="https://www.microsoft.com/playready/partners/">Microsoft PlayReady Partners</a></p>
</li>
</ul>
<p>Here are some third-party service providers we are aware of, listed without recommendation or in any particular order:</p>
<ul>
<li><p>Axinom</p>
</li>
<li><p>BuyDRM</p>
</li>
<li><p>CastLabs</p>
</li>
<li><p>ExpressPlay</p>
</li>
<li><p>EZDRM</p>
</li>
<li><p>Inka Entworks</p>
</li>
<li><p>Vualto</p>
</li>
<li><p>Verimatrix</p>
</li>
</ul>
<p>After signing a contract with these manufacturers, they will provide back-end or related SDKs, and enterprises can use their servers as content authentication hosts to verify users' video authorization range. They usually support multiple encryption CDM modules. They also provide video encryption methods. After encrypting the video with these tools, it is then distributed to users' browsers. The videos downloaded by the browser cannot be played by ordinary players but must be decrypted in real-time by the decryption module on your website.</p>
<p>If you simply want to host videos, there are also dedicated DRM platforms for video hosting. You just need to upload videos from their backend and embed them on your website to use them. These platforms even offer dynamic watermarking features, creating different video watermarks for each viewer to prevent recording. However, note that this real-time watermark creation mechanism is relatively more expensive.</p>
<ul>
<li><p><a target="_blank" href="https://www.vdocipher.com/">VdoCipher</a></p>
</li>
<li><p><a target="_blank" href="https://flowplayer.com/">Flowplayer</a></p>
</li>
<li><p><a target="_blank" href="https://www.muvi.com/">Muvi</a></p>
</li>
<li><p><a target="_blank" href="https://nichevid.com/">Nichevid</a></p>
</li>
</ul>
<h3 id="heading-what-business-models-are-available"><strong>What Business Models Are Available</strong></h3>
<p>Most DRM and agents support several business models, which can be chosen according to enterprise needs:</p>
<ul>
<li><p>Pay by duration</p>
</li>
<li><p>Permission based on authorization status</p>
</li>
<li><p>Pay-per-use</p>
</li>
<li><p>Short-term rental</p>
</li>
<li><p>One-time purchase</p>
</li>
<li><p>Ad-supported models</p>
</li>
</ul>
<p>And video resources can be distributed in two common modes:</p>
<ul>
<li><p>Complete download</p>
</li>
<li><p>Progressive download (download as you play)</p>
</li>
</ul>
<p>These features, whether Widevine or PlayReady, are provided on major platforms with ready-made management modes and SDK packages, allowing developers to focus on the architecture for commercial logic.</p>
<h3 id="heading-can-i-set-up-my-own-licensing-server"><strong>Can I Set Up My Own Licensing Server?</strong></h3>
<p>If you prefer not to use third-party licensing providers and wish to set up your own Widevine or PlayReady server, it's possible but more complicated. For Google Widevine, general public access to the Server SDK isn't available. You need to <a target="_blank" href="https://www.widevine.com/training">apply to become their distributor</a> and pass a test to get the server code. While PlayReady offers free server tools, <a target="_blank" href="https://docs.microsoft.com/en-us/playready/overview/license-server#development-and-deployment-of-a-playready-license-server">you still must contact Microsoft</a> to obtain the server SDK. Practically, it's often advised to start with a reputable DRM partner for faster business model implementation.</p>
<h3 id="heading-can-i-build-my-cdm-module-without-drm-vendors">Can I Build My CDM Module Without DRM Vendors</h3>
<p>The ClearKey protocol is available for any browser, you may simply implement ClearKey to build your own encrypt/decrypt logic for your media resources. However, you must know that ClearKey uses unencrypted keys to decrypt resources, it is not very safe to protect your data, so we recommend only using ClearKey for the test process.</p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>EME and Web DRM provide a universal encryption mechanism across manufacturers, filling a gap in HTML5 environments akin to DRM mechanisms in Flash and Silverlight.</p>
<p>However, even with EME, it's not 100% piracy-proof. It increases the difficulty of unauthorized access and reduces the quality of the resources obtained. For instance, Widevine's L1 encryption has been claimed to be cracked by certain groups, but not publicly, <a target="_blank" href="https://cyware.com/news/googles-widevine-l3-drm-cracked-by-a-security-researcher-eaed58ca">while L3 encryption is more commonly broken into</a>, albeit with lower quality.</p>
<p>As mentioned in the <a target="_blank" href="https://blog.uniauth.com/web-drm-1-digital-content-protection">previous article</a>, replay and recording attacks are undefendable since any content eventually needs to be converted into physical signals visible to the naked eye, and these signals can be recorded by additional devices.</p>
<p>Web DRM primarily verifies user payment and access rights to specific resources. For those intent on copying resources elsewhere, it remains ineffective.<br />If you're seeking to protect all your digital assets from being copied, EME can only increase the difficulty but cannot provide absolute assurance of perfect protection.</p>
<h2 id="heading-related-links"><strong>Related Links</strong></h2>
<ul>
<li><p><a target="_blank" href="https://developers.google.com/web/fundamentals/media/eme">What is EME? (Google)</a></p>
</li>
<li><p><a target="_blank" href="https://www.vdocipher.com/blog/2018/11/encrypted-media-extensions-eme/">Introduction to Encrypted Media Extensions (EME) For DRM Systems</a></p>
</li>
<li><p><a target="_blank" href="https://medium.com/@RossetPaul/encrypted-media-extension-eme-api-watching-protected-video-content-on-the-web-1ac7b175c92d">Encrypted Media Extension (EME) API, watching protected video content on the web</a></p>
</li>
<li><p><a target="_blank" href="https://pallycon.com/blog/how-to-estimate-saas-drm-license-cost/">How to Estimate SaaS DRM License Cost</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Web DRM, an Overview (1) - Digital Content Protection]]></title><description><![CDATA[Protecting copyrighted content has always been a priority for many businesses, from the past to the present. In the digital era, this task has become more challenging due to the ease of copying content. Modern enterprises now rely on a range of strat...]]></description><link>https://blog.uniauth.com/web-drm-1-digital-content-protection</link><guid isPermaLink="true">https://blog.uniauth.com/web-drm-1-digital-content-protection</guid><category><![CDATA[eme]]></category><category><![CDATA[web drm]]></category><category><![CDATA[drm]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Simon Asika]]></dc:creator><pubDate>Wed, 06 Dec 2023 15:39:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1701877077912/252cd1e1-3a50-4c27-adc5-adc27498e996.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Protecting copyrighted content has always been a priority for many businesses, from the past to the present. In the digital era, this task has become more challenging due to the ease of copying content. Modern enterprises now rely on a range of strategies to prevent piracy.</p>
<p>Due to the open nature of the internet era, browsers cannot prevent users from accessing the source code. This makes protecting intellectual property on websites quite challenging. This article specifically introduces digital content protection strategies in the Internet age.</p>
<h2 id="heading-what-is-drm"><strong>What is DRM?</strong></h2>
<p>For protecting digital intellectual property, the most common method is <a target="_blank" href="https://en.wikipedia.org/wiki/Digital_rights_management">DRM (Digital Rights Management)</a>. In simple terms, it manages how and whether consumers can "copy" digital assets. People who are familiar with gaming will recognize DRM, as many modern games use it to prevent copying and require identity verification for play.</p>
<p>Early DRM mainly used streaming and real-time decryption, especially in DVDs. This involved encrypting DVD content, which was then decrypted in real-time by authorized devices during playback. In recent years, large games often use tamper-proof mechanisms, wrapping the game program in a layer that decrypts command codes in real-time, which can significantly reduce performance.</p>
<p>Since DVDs are usually decrypted quickly by hardware, this wasn't a big issue. However, in modern 3D games where CPU resources are maximized, DRM's impact on performance often draws complaints from players. This is why DRM is notorious in the gaming world.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1400/format:webp/0*HsAq9WoKMUgfuZGb.jpg" alt /></p>
<blockquote>
<p>Image: <a target="_blank" href="https://arstechnica.com/gaming/2017/11/ubisoft-denies-pc-drm-is-slowing-down-assassins-creed-origins/">Assassin's Creed: Origins' was criticized by players for performance issues caused by its dual DRM protection. While Ubisoft denies this reason</a>.</p>
</blockquote>
<h3 id="heading-various-forms-of-drm"><strong>Various Forms of DRM</strong></h3>
<p>DRM isn't just real-time decryption. Practically, any technology that prevents the abuse of intellectual property is considered DRM. For example, some games don't use real-time decryption but require a constant internet connection to verify the player's identity.</p>
<p>Other common methods include:</p>
<ul>
<li><p>Serial number authentication.</p>
</li>
<li><p>Connecting to a server for membership registration and identity verification.</p>
</li>
<li><p>Server control over the number of devices a software can be installed on.</p>
</li>
<li><p>Limiting the number of copies or downloads.</p>
</li>
<li><p>Hardware to anti skimming or recording.</p>
</li>
<li><p>Using specialized devices to view/access resources.</p>
</li>
<li><p>Watermarks (yes, just a simple tracking of leaking data also considered as a DRM).</p>
</li>
<li><p>Metadata (declaring copyright in the metadata of files or photos).</p>
</li>
<li><p>Monitoring users' behavior and reporting to the backend.</p>
</li>
<li><p>Detecting if software or resource content has been tampered with, and stopping operation if so.</p>
</li>
<li><p>Using a central marketplace to sell resources and centrally verify identities (similar to the Apple App Store or Steam).</p>
</li>
<li><p>Requiring an online download after purchase.</p>
</li>
</ul>
<p>There are many methods, some even raising privacy concerns. However, due to commercial interests, many manufacturers still opt for these protection mechanisms.</p>
<h2 id="heading-how-is-website-drm-implemented"><strong>How is Website DRM Implemented?</strong></h2>
<p>Let's talk about DRM on websites, which commonly protects audio-visual content, ebooks, software, or resource materials. However, implementing DRM on websites is generally ineffective.</p>
<h3 id="heading-why-is-website-drm-considered-ineffective"><strong>Why is Website DRM Considered Ineffective?</strong></h3>
<p>The reason is that web browsers are open environments. The JavaScript code isn't compiled, so anyone can see the source code. In such an environment, any encryption program, if executed on the browser side, can be easily cracked.</p>
<p>Moreover, all content viewed in a browser—audio, video, images, text—must be downloaded to memory to display, and browsers easily allow users to open and save these resources.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:1400/format:webp/1*mny2_PsY5u66rQe8yx3OHQ.jpeg" alt /></p>
<blockquote>
<p>This image shows how easy it is to capture a video's original file from a website using a browser.</p>
</blockquote>
<p>Due to this openness, any encryption can't prevent the final action of saving files from the record, making it pointless to encrypt resources.</p>
<h2 id="heading-what-other-methods-exist-for-web-drm"><strong>What Other Methods Exist for Web DRM?</strong></h2>
<p>As mentioned before, DRM isn't just about encryption. Any method that can prevent copying or make stealing more difficult is considered DRM. Here are some common DRM methods used online, none perfect, but they make illegal copying harder.</p>
<h3 id="heading-for-graphic-and-text-resources"><strong>For Graphic and Text Resources</strong></h3>
<ul>
<li><p>Locking right-click to block copying.</p>
</li>
<li><p>Converting text into images.</p>
</li>
<li><p>Verifying member identity for access.</p>
</li>
<li><p>Server outputs a small chunk of graphics and text at a time, with identity verification for each access.</p>
</li>
<li><p>Using specialized devices or software to view graphics and text.</p>
</li>
<li><p>Embedding watermarks in images.</p>
</li>
<li><p>Automatically adding copyright statements when copying text.</p>
</li>
</ul>
<h3 id="heading-for-downloadable-resources-software-or-virtual-assets"><strong>For Downloadable Resources (Software or Virtual Assets)</strong></h3>
<ul>
<li><p>Controlling the allowed times of downloads.</p>
</li>
<li><p>Allowing downloads only after member identity verification.</p>
</li>
<li><p>Attaching a time-limited certificate to the download URL, so it expires after a certain period.</p>
</li>
<li><p>Allowing unlimited downloads, but requiring online serial number or identity verification.</p>
</li>
</ul>
<h3 id="heading-for-audiovideo-resources"><strong>For Audio/Video Resources</strong></h3>
<ul>
<li><p>Attaching a time-limited certificate to the audio-visual access URL, so it expires after a certain period.</p>
</li>
<li><p>Embedding trademarks or member account watermarks in the audiovisual content.</p>
</li>
<li><p>Using live streaming to play audio/video (downloading content as it plays, not storing the entire file in memory).</p>
</li>
<li><p>Splitting audio-visual content into chunks, each lasting about 5 seconds to the browser, makes copying extremely difficult.</p>
</li>
<li><p>Encrypting audio-visual content, with each member having a unique key for decryption, preventing sharing.</p>
</li>
</ul>
<p>These are some of the more common anti-copying measures on the market. However, they mainly increase the difficulty of copying but can't completely stop someone who really wants to steal them. In addition, using server output instead static file access is a common solution because the server can verify identity with each access.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1701875543819/6517dbc0-92eb-49b7-9aa7-a9a28b09dbe2.jpeg" alt class="image--center mx-auto" /></p>
<blockquote>
<p>Image: Limiting times of downloads is a common DRM mechanism, The screenshot is <a target="_blank" href="https://www.datavideovirtualset.com/">DatavideoVirtualset</a> website.</p>
</blockquote>
<h2 id="heading-common-methods-of-cracking-drm"><strong>Common Methods of Cracking DRM</strong></h2>
<h3 id="heading-intercepting-or-stealing-the-decryption-keys">Intercepting or Stealing the Decryption Keys</h3>
<p>Whether by hacking, reading from memory, or leaks from internal employees, owning the decryption key means directly unlocking the confidential asset and then copying it into another unencrypted version.</p>
<h3 id="heading-exploiting-software-and-hardware-vulnerabilities">Exploiting Software and Hardware Vulnerabilities</h3>
<p>Software and hardware can have vulnerabilities, especially in closed systems where flaws are not publicly known or fixed. Usually, privilege escalation is used to obtain the key.</p>
<h3 id="heading-removing-watermarks">Removing Watermarks</h3>
<p>Rough protection methods are broken by rough methods if the stealer doesn't matter the image or audio-visual quality.</p>
<h3 id="heading-recording-or-replay-attacks">Recording or Replay Attacks</h3>
<p>This major method of cracking DRM involves recording content during post-decryption transmission. Alternatively, all graphics and text can be screenshotted, and all audio and video can be recorded. Even if we have the hardware anti-recording protection, a smartphone can easily record the content. However, this method is not suitable for games, where the main purpose is the interactive experience.</p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>Although DRM is important for protecting commercial interests, it can't 100% protect digital assets from stealing in the real world. It's mainly used to broadly verify whether purchasers have access rights. Anti-theft still requires media manipulation and legal deterrence to be effective.</p>
<p>Additionally, despite being easily cracked, DRM persists partly due to business and political factors. Companies selling digital resources might need to assure shareholders or original creators that the resources won't be leaked. Claiming to have DRM technology is a good way to gain trust from licensors and to some extent, take responsibility for protecting assets.</p>
<p><img src="https://www.techspot.com/images2/news/bigimage/2011/2011-05-27-image-1.jpg" alt class="image--center mx-auto" /></p>
<blockquote>
<p>Image: For instance, "<a target="_blank" href="https://www.techspot.com/news/43989-the-witcher-2-patch-11-removes-drm-boosts-framerate.html">The Witcher 2" removed DRM a few days after its release</a> due to its significant impact on performance.</p>
</blockquote>
<p>As for website anti-theft, in the open culture of the Web era, all browsers can't prevent content from being copied and extracted. Thus, DRM can only control that un-purchased users can't access resources, but copying elsewhere after purchase is almost unstoppable. Creating more anti-theft features is a trade off, that may lead to additional costs and losses. For example, the developer of "The Witcher 2" released an update to remove DRM a few days after launching the game, recognizing its significant impact on performance.</p>
<p>However, for audio-visual resources, there are solutions. In 2017, the W3C approved a standard for Web DRM: <a target="_blank" href="https://zh.wikipedia.org/wiki/%E5%8A%A0%E5%AF%86%E5%AA%92%E4%BD%93%E6%89%A9%E5%B1%95">EME (Encrypted Media Extensions)</a>, which can encrypt and decrypt audiovisual content in browsers. Although it's new and not widely used, big companies like Netflix and Spotify have already started using it. It could be a potential solution for audio-visual content theft prevention.</p>
<p>If you want to know more about EME, please see our next article.</p>
]]></content:encoded></item><item><title><![CDATA[Using Nested Set Model to Build Hierarchical Data]]></title><description><![CDATA[I've been using the Nested set model for a while in Windwalker Framework, as it's built into its core ORM package. However, I realized that there isn't much discussion about this model in the dev community.
The Nested set model is a data model design...]]></description><link>https://blog.uniauth.com/nested-set-model</link><guid isPermaLink="true">https://blog.uniauth.com/nested-set-model</guid><category><![CDATA[nested set model]]></category><category><![CDATA[Hierarchical Data]]></category><category><![CDATA[Tree]]></category><category><![CDATA[nested]]></category><dc:creator><![CDATA[Simon Asika]]></dc:creator><pubDate>Mon, 04 Dec 2023 05:11:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1701667098942/25084aea-5a36-47c2-855d-939bd8acfff9.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I've been using the <a target="_blank" href="http://en.wikipedia.org/wiki/Nested_set_model">Nested set model</a> for a while in <a target="_blank" href="https://windwalker.io/">Windwalker Framework</a>, as it's built into its core ORM package. However, I realized that there isn't much discussion about this model in the dev community.</p>
<p>The Nested set model is a data model designed for efficiently handling tree node structures. It allows us to retrieve nodes, calculate node counts, or load whole tree data without traversing the entire tree.</p>
<h2 id="heading-about-traditional-adjacency-list-model"><strong>About</strong> Traditional <strong>Adjacency List Model</strong></h2>
<p>First, let's discuss the traditional design for handling nested structures, using a data table that contains a <code>parent_id</code> for its tree structure.</p>
<pre><code class="lang-sql">Table: `tree`

| id | parent_id | title |
|<span class="hljs-comment">----|-----------|-------|</span>
| 1  | 0         | ROOT  |
| 2  | 1         | four  |
| 3  | 1         | node  |
| 4  | 2         | node  |
| 5  | 2         | node  |
| 6  | 3         | node  |
</code></pre>
<p>As we can see, each record has a <code>parent_id</code> pointing to its parent node. To retrieve child nodes, an SQL query would look like this:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> <span class="hljs-string">`tree`</span> <span class="hljs-keyword">WHERE</span> <span class="hljs-string">`parent_id`</span> = <span class="hljs-number">1</span>;
</code></pre>
<p>This method is straightforward and easy to understand. However, its downside is evident when trying to fetch multi-level data or calculate the number of nodes, as it requires recursive operations, heavily burdening the database.</p>
<h2 id="heading-solution-nested-set-model"><strong>Solution: Nested Set Model</strong></h2>
<p>The <strong>Nested Set Model</strong> is an excellent solution to this issue.</p>
<p>Let's examine the tree structure of the Nested set model. Each node has a left and right key, usually named <code>lft</code> and <code>rgt</code>. Assume we start with a root node A:</p>
<pre><code class="lang-sql">        A (1,2)
</code></pre>
<p>When we add a node B under A, it changes to:</p>
<pre><code class="lang-sql">        A (1,4)
           |
           |         
        B (2,3)
</code></pre>
<p>Then, adding a node C:</p>
<pre><code class="lang-sql">        A (1,6)
           |
    <span class="hljs-comment">---------------</span>
    |             |
B (2,3)        C (4,5)
</code></pre>
<p>Clearly, the left and right keys of B and C are wrapped within A. To retrieve B and C, an SQL query would be:</p>
<pre><code class="lang-sql"><span class="hljs-comment">-- Assuming a typical workflow, we might first </span>
<span class="hljs-comment">-- retrieve A's data using ORM</span>

<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> <span class="hljs-string">`tree`</span> <span class="hljs-keyword">WHERE</span> <span class="hljs-string">`id`</span> = <span class="hljs-number">1</span>;

<span class="hljs-comment">-- Then, using A's lft and rgt to query all children</span>

<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> <span class="hljs-string">`tree`</span> <span class="hljs-keyword">WHERE</span> <span class="hljs-string">`lft`</span> &gt; <span class="hljs-number">1</span> <span class="hljs-keyword">AND</span> <span class="hljs-string">`rgt`</span> &lt; <span class="hljs-number">6</span>

<span class="hljs-comment">-- To include A, add equals sign</span>

<span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> <span class="hljs-string">`tree`</span> <span class="hljs-keyword">WHERE</span> <span class="hljs-string">`lft`</span> &gt;= <span class="hljs-number">1</span> <span class="hljs-keyword">AND</span> <span class="hljs-string">`rgt`</span> &lt;= <span class="hljs-number">6</span>

<span class="hljs-comment">-- This approach can implementable in any programming language</span>
</code></pre>
<p>The advantage here is evident, using <code>lft</code> and <code>rgt</code> keys, we can easily retrieve whole children nodes. Refer to the following image:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1701665026204/486af035-9d1a-43a6-861f-bce47cc010cb.jpeg" alt class="image--center mx-auto" /></p>
<p>Using <code>lft &gt; 1 AND rgt &lt; 22</code>, we can retrieve all nodes at once, whereas the traditional adjacency list model might require up to 5 queries to fetch or calculate all child nodes.</p>
<h2 id="heading-initializing-a-tree"><strong>Initializing a Tree</strong></h2>
<p>Now, let's dive into some real-world examples.</p>
<p>A key point of Nested set is to always have a root node, which is the starting point for all nodes and generally not used. Initially, we need to create a table with <code>parent_id</code>, <code>lft</code>, <code>rgt</code>. The <code>parent_id</code> is used for upward queries. Additionally, to easily control query levels, we can add a <code>level</code> column to track the current level.</p>
<p>Initializing a category table:</p>
<pre><code class="lang-sql">| id | parent_id | title | lft | rgt | level |
|<span class="hljs-comment">----|-----------|-------|-----|-----|-------|</span>
| 1  | 0         | ROOT  |  1  |  2  |   1   |
</code></pre>
<p>Here's a simple creation syntax:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-keyword">IF</span> <span class="hljs-keyword">NOT</span> <span class="hljs-keyword">EXISTS</span> <span class="hljs-string">`categories`</span> (
  <span class="hljs-string">`id`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> AUTO_INCREMENT,
  <span class="hljs-string">`parent_id`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">10</span>) <span class="hljs-keyword">UNSIGNED</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">'0'</span>,
  <span class="hljs-string">`lft`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">'0'</span>,
  <span class="hljs-string">`rgt`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">'0'</span>,
  <span class="hljs-string">`level`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">10</span>) <span class="hljs-keyword">UNSIGNED</span> <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-string">'0'</span>,
  <span class="hljs-string">`title`</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">255</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>,
  PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`id`</span>),
  <span class="hljs-keyword">KEY</span> <span class="hljs-string">`idx_left_right`</span> (<span class="hljs-string">`lft`</span>,<span class="hljs-string">`rgt`</span>)
) <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CHARSET</span>=utf8;

<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`categories`</span> <span class="hljs-keyword">VALUE</span> (<span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-string">'ROOT'</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>);
</code></pre>
<h2 id="heading-preparing-example-data"><strong>Preparing Example Data</strong></h2>
<p>Here, we prepare some example data, including category and article tables:</p>
<h3 id="heading-category"><strong>Category</strong></h3>
<pre><code class="lang-sql">| id | parent_id | title | lft | rgt | level |
|<span class="hljs-comment">----|-----------|-------|-----|-----|-------|</span>
| 1  | 0         | ROOT  |  1  |  10 |   1   |
| 2  | 1         | A     |  2  |  7  |   2   |
| 3  | 2         | B     |  3  |  4  |   3   |
| 4  | 2         | C     |  5  |  6  |   3   |
| 5  | 1         | D     |  8  |  9  |   2   |
</code></pre>
<h3 id="heading-articles"><strong>Articles</strong></h3>
<pre><code class="lang-sql">| id | title      | catid |
|<span class="hljs-comment">----|------------|-------|</span>
| 1  | Article 1  |  1    |
| 2  | Article 2  |  2    |
| 3  | Article 3  |  3    |
| 4  | Article 4  |  3    |
| 5  | Article 5  |  4    |
| 6  | Article 6  |  5    |
</code></pre>
<h2 id="heading-some-simple-query-examples"><strong>Some Simple Query Examples</strong></h2>
<p>Retrieve all articles under all categories of A (very useful for blog categories):</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-string">`a`</span>.*, <span class="hljs-string">`b`</span>.* 
    <span class="hljs-keyword">FROM</span> <span class="hljs-string">`articlea`</span> <span class="hljs-keyword">AS</span> <span class="hljs-string">`a`</span>
    <span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> <span class="hljs-string">`categories`</span> <span class="hljs-keyword">AS</span> b <span class="hljs-keyword">ON</span> <span class="hljs-string">`a`</span>.<span class="hljs-string">`catid`</span> = <span class="hljs-string">`b`</span>.<span class="hljs-string">`id`</span>
<span class="hljs-keyword">WHERE</span>
    <span class="hljs-string">`b`</span>.<span class="hljs-string">`lft`</span> &gt;= <span class="hljs-number">2</span> <span class="hljs-keyword">AND</span> <span class="hljs-string">`b`</span>.<span class="hljs-string">`rgt`</span> &lt;= <span class="hljs-number">7</span>

<span class="hljs-comment">-- OR</span>

    <span class="hljs-string">`b`</span>.<span class="hljs-string">`lft`</span> <span class="hljs-keyword">BETWEEN</span> <span class="hljs-number">2</span> <span class="hljs-keyword">AND</span> <span class="hljs-number">7</span>
</code></pre>
<p>Limiting Levels:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-string">`a`</span>.*, <span class="hljs-string">`b`</span>.* 
    <span class="hljs-keyword">FROM</span> <span class="hljs-string">`articles`</span> <span class="hljs-keyword">AS</span> <span class="hljs-string">`a`</span>
    <span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> <span class="hljs-string">`categories`</span> <span class="hljs-keyword">AS</span> b <span class="hljs-keyword">ON</span> <span class="hljs-string">`a`</span>.<span class="hljs-string">`catid`</span> = <span class="hljs-string">`b`</span>.<span class="hljs-string">`id`</span>
<span class="hljs-keyword">WHERE</span>
    <span class="hljs-string">`b`</span>.<span class="hljs-string">`lft`</span> &gt;= <span class="hljs-number">2</span> <span class="hljs-keyword">AND</span> <span class="hljs-string">`b`</span>.<span class="hljs-string">`rgt`</span> &lt;= <span class="hljs-number">7</span> 
    <span class="hljs-keyword">AND</span> 
    <span class="hljs-string">`b`</span>.<span class="hljs-string">`level`</span> &lt; <span class="hljs-number">2</span>
</code></pre>
<p>Reverse Query to Find All Ancestors of Node B:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-string">`categories`</span>.* 
    <span class="hljs-keyword">FROM</span> <span class="hljs-string">`categories`</span> <span class="hljs-keyword">AS</span> <span class="hljs-string">`node`</span>, <span class="hljs-string">`categories`</span> <span class="hljs-keyword">AS</span> <span class="hljs-string">`parent`</span>
<span class="hljs-keyword">WHERE</span>
    <span class="hljs-string">`node`</span>.<span class="hljs-string">`lft`</span> <span class="hljs-keyword">BETWEEN</span> <span class="hljs-string">`parent`</span>.<span class="hljs-string">`lft`</span> <span class="hljs-keyword">AND</span> <span class="hljs-string">`parent`</span>.<span class="hljs-string">`rgt`</span>
    <span class="hljs-keyword">AND</span> <span class="hljs-string">`node`</span>.<span class="hljs-string">`id`</span> = <span class="hljs-number">3</span>
</code></pre>
<p>Adding a Node Before B:</p>
<pre><code class="lang-sql"><span class="hljs-comment">-- First, make room, all rgt, lft + 2</span>

<span class="hljs-keyword">UPDATE</span> <span class="hljs-string">`categories`</span> <span class="hljs-keyword">SET</span>
    <span class="hljs-string">`rgt`</span> = <span class="hljs-string">`rgt`</span> + <span class="hljs-number">2</span>,
    <span class="hljs-string">`lft`</span> = <span class="hljs-string">`lft`</span> + <span class="hljs-number">2</span>
<span class="hljs-keyword">where</span>
    <span class="hljs-string">`lft`</span> &gt; <span class="hljs-number">2</span>

<span class="hljs-comment">-- Then insert the node</span>

<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> <span class="hljs-string">`categories`</span> <span class="hljs-keyword">VALUE</span> (:<span class="hljs-keyword">id</span>, <span class="hljs-string">'New Article'</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">3</span>);
</code></pre>
<p>This approach can be easily implemented in any language.</p>
<h2 id="heading-extending-neste-set-model">Extending Neste Set Model</h2>
<p>Generally, only the <code>parent_id</code>, <code>lft</code> and <code>rgt</code> are required fields in Nested Set Model. Furthermore, additional fields can be added to extend various functions. For example, in this article, we add <code>level</code> to control the node levels. Some implementation will add an <code>alias</code> and <code>path</code> field, which looks like <code>parent/parent2/child/child2</code>. This is useful in the application itself for quickly comparing node levels.</p>
<p>You may also create a Multi-Tree Neseted Set Table, Just add a <code>root_id</code> or <code>master_id</code> to hold the ROOT node ID for every node, then adding this where control to every query:</p>
<pre><code class="lang-sql">WHERE `root_id` = :rootId
</code></pre>
<p>that you can limit every read / write operation under a root node.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Nested set model has pros on the loading and retrieving performance. However, the downside is that adding or moving nodes requires traversing the entire tree to rebuild the index, which is not very efficient.</p>
<p>For general applications, it's like trading back-end storage operation performance for front-end reading performance, which is also a solution in high-traffic systems.</p>
<h3 id="heading-related-links">Related Links</h3>
<ul>
<li><p><a target="_blank" href="https://github.com/windwalker-io/orm">Windwalker ORM</a></p>
</li>
<li><p><a target="_blank" href="https://docs.joomla.org/Using_nested_sets">Joomla Nested Set Guide</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/lazychaser/laravel-nestedset">Laravel Nested Set</a></p>
</li>
<li><p><a target="_blank" href="http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/hierarchical-data.html">Doctrine Hierarchical Data</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Can I Encrypt PHP  Source Code? How Can Enterprises Protect Their PHP Code?]]></title><description><![CDATA[PHP is one of the most common server-side programming languages for websites, widely used in developing various web applications. Its flexible coding style and powerful functionality have made it popular worldwide among web developers. However, since...]]></description><link>https://blog.uniauth.com/encrypt-php-source-code</link><guid isPermaLink="true">https://blog.uniauth.com/encrypt-php-source-code</guid><category><![CDATA[PHP]]></category><category><![CDATA[encryption]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Simon Asika]]></dc:creator><pubDate>Sat, 02 Dec 2023 11:00:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1701516547188/5b4dcdff-c043-4f56-bc89-518a94509d84.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>PHP is one of the most common server-side programming languages for websites, widely used in developing various web applications. Its flexible coding style and powerful functionality have made it popular worldwide among web developers. However, since PHP is open-source, enterprises often worry about their source code being easily viewed or copied.</p>
<p>This brings us to our topic: Can PHP source code in PHP be encrypted or compiled? The answer to this question involves not only the confidentiality of the code but also the performance and security of web applications.</p>
<h2 id="heading-the-basic-working-principle-of-php-source-code">The Basic Working Principle of PHP Source Code</h2>
<p>To answer this question, we first need to understand the basic working principle of PHP. PHP is an interpreted language, meaning it is read and interpreted line by line by the PHP interpreter at runtime, rather than being pre-compiled into machine language. When a user requests a PHP page, the PHP interpreter on the server interprets and executes the PHP source code of that page, sending the generated HTML content to the user's browser.</p>
<p>This working method has a drawback: the source code can be viewed by anyone with access to the server. If your code contains sensitive information, such as database passwords, or if you don't want your business logic to be understood by competitors or hackers, this can be a problem.</p>
<h2 id="heading-encrypting-php-source-code">Encrypting PHP Source Code</h2>
<p>To address this issue, developers can choose to encrypt their PHP source code. Common PHP source code encryption tools include:</p>
<ul>
<li><p><a target="_blank" href="http://www.zend.com/en/products/zend-guard">Zend Guard</a></p>
</li>
<li><p><a target="_blank" href="http://www.ioncube.com/php_encoder.php">ionCube</a></p>
</li>
<li><p><a target="_blank" href="https://www.sourceguardian.com/">Source Guardian</a></p>
</li>
<li><p><a target="_blank" href="https://www.phpshield.com/">PHP Shield</a></p>
</li>
<li><p><a target="_blank" href="https://phpbolt.com/">PhpBolt</a></p>
</li>
<li><p><a target="_blank" href="https://business.swoole.com/compiler.html">Swoole Compiler</a></p>
</li>
</ul>
<p>These tools can convert PHP source code into a form that is difficult for humans to read, thereby protecting the privacy of the source code.</p>
<p>The basic principle of using these tools is to encode the source code into a binary format or obfuscate its syntax structure, making it difficult to understand or modify. Then, when running the encrypted code on the server, a corresponding decoder or loader is needed to convert the encrypted code back into executable PHP code. This way, even if someone obtains your PHP code, they cannot understand or use it unless they have the key to the decoder.</p>
<h3 id="heading-zend-guard">Zend Guard</h3>
<p><img src="https://www.zend.com/sites/default/files/styles/social_preview_image/public/image/2019-08/image-blog-zend-guard-and-php-7.jpg?itok=W3m-pqJ9" alt="Zend Guard" class="image--center mx-auto" /></p>
<p>Zend Guard is a professional PHP encryption product offered by Zend Technologies (a company founded by Zeev Suraski and Andi Gutmans, creators of PHP). It is used to protect and encode the source code of PHP applications, preventing unauthorized use and reverse engineering. Zend Guard provides strong code encryption and obfuscation capabilities, encrypting PHP source code into a form that is difficult to read and modify, thereby protecting the intellectual property rights of developers.</p>
<h3 id="heading-ioncube">ionCube</h3>
<p><img src="https://www.ioncube.com/images/logo_text/ioncube_logo_720.png" alt="ioncube" class="image--center mx-auto" /></p>
<p>ionCube is a powerful PHP encryption tool that can effectively protect PHP source code from piracy or unauthorized modification. With ionCube, developers can encode PHP code into a binary form that can only be decoded through the ionCube Loader. ionCube also supports various PHP versions and seamlessly integrates with most web servers, making it widely acclaimed among PHP developers.</p>
<h3 id="heading-source-guardian">Source Guardian</h3>
<p><img src="https://gdm-catalog-fmapi-prod.imgix.net/ProductLogo/d1575e0f-09cd-4035-9fa9-9e0c43975612.png?w=90&amp;h=90&amp;fit=max&amp;dpr=3&amp;auto=format&amp;q=50" alt="SourceGuardian" class="image--center mx-auto" /></p>
<p>SourceGuardian is a professional PHP encoding and encryption software, mainly used to protect PHP source code from being copied, modified, or pirated. With SourceGuardian, developers can encrypt their PHP programs to ensure the security of their intellectual property. In addition to encryption, SourceGuardian also offers features like expiration date restrictions and domain limitations, helping developers control the deployment and distribution of their programs.</p>
<h3 id="heading-php-shield">PHP Shield</h3>
<p>PHP Shield is an encryption tool for protecting PHP source code. It compiles PHP code into bytecode and then encrypts it to prevent the source code from being viewed or modified. PHP Shield offers an easy-to-use interface, making the coding and encryption process quite simple and straightforward. Moreover, the encrypted code it generates can run on various platforms, requiring only the free loader from PHP Shield.</p>
<h3 id="heading-phpbolt">PhpBolt</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1701517025984/bd14d551-848f-4950-b027-301d20fb20fe.jpeg" alt class="image--center mx-auto" /></p>
<p>PhpBolt is a PHP extension for encrypting scripts, offering high performance with minimal impact on execution speed. It stands out for its compatibility with various PHP versions and its robust security features like domain and IP restrictions. Unlike some other encryption tools, PhpBolt focuses on ease of use and efficient execution, making it ideal for securing commercial PHP applications without compromising functionality.</p>
<h3 id="heading-swoole-compiler">Swoole Compiler</h3>
<p>Swoole Compiler is an encryption and client authorization solution for PHP code launched by the official Swoole team. It compiles PHP programs into binary instructions to protect your source code. Unlike traditional PHP encryptors like Zend Guard, Swoole Compiler does not have a software interface; it provides an API, allowing Swoole Compiler to be integrated into your packaging and distribution platform, making it fully programmable.</p>
<h2 id="heading-enhancing-system-security">Enhancing System Security</h2>
<p>Many enterprises worry about source code leakage, not just for intellectual property rights, but also for the risk of information security breaches. The maintrend view in recent years is that any sufficiently robust software should be secure even if its source code is fully known to outsiders. For example, strong encryption algorithms, high-standard security management, and user access control are all important aspects. With the right development philosophy, even if outsiders obtain the source code, they should not be able to access any functionality of the system. If they can, it indicates the existence of a "backdoor," which should not happen.</p>
<p>For companies using PHP, it's worth considering these aspects of security policy and strengthening the security management of the development team, such as implementing automated regular vulnerability scanning and source code quality control.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>PHP source code can be encrypted using encryption tools, thereby enhancing its confidentiality. However, since PHP is an interpreted language, it cannot be directly compiled into machine language like compiled languages.</p>
<p>Whether you need to encrypt PHP source code depends entirely on the specific needs of your enterprise. If your PHP code contains sensitive information or involves unique business logic, and you are concerned that its disclosure could pose a business risk, then trying to encrypt PHP source code might be a good choice. Alternatively, starting from the source of development for information security management to ensure that the system has no backdoors is also an appropriate solution.</p>
<h3 id="heading-see-also">See Also</h3>
<ul>
<li><p><a target="_blank" href="https://speakerdeck.com/albertcht/source-code-protection-techniques-in-php">Source Code Protection Techniques in PHP</a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/pulse/using-php-encoders-safeguard-source-code-walkthrough-phpbolt-riaz/">Using PHP Encoders to Safeguard Source Code: A Walkthrough with phpBo</a>lt</p>
</li>
<li><p><a target="_blank" href="https://www.quora.com/Ist-there-an-easy-way-to-protect-PHP-Code">Is there an easy way to protect PHP Code?</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[[Secure 101] What are 2FA and MFA? Does My Website Need These Features?]]></title><description><![CDATA[As digitalization becomes increasingly prevalent, we rely more on websites for various aspects of life and work, including shopping, banking, and social media. However, this convenience also brings many security risks. We often see news about online ...]]></description><link>https://blog.uniauth.com/what-are-2fa-and-mfa</link><guid isPermaLink="true">https://blog.uniauth.com/what-are-2fa-and-mfa</guid><category><![CDATA[Two-factor authentication (2FA) ]]></category><category><![CDATA[2FA]]></category><category><![CDATA[MFA]]></category><category><![CDATA[authentication]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Simon Asika]]></dc:creator><pubDate>Mon, 27 Nov 2023 10:46:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1701111322805/fb3281f6-6c5e-4c45-9002-d8617705fbcd.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>As digitalization becomes increasingly prevalent, we rely more on websites for various aspects of life and work, including shopping, banking, and social media. However, this convenience also brings many security risks. We often see news about online fraud, data breaches, and even identity theft, highlighting the importance of website security.</p>
<p>Website security is crucial for protecting users' personal information. Most account theft incidents stem from hackers stealing passwords to access websites. Therefore, to protect both users and their own interests, many international websites have started to implement different modes of identity verification, replacing simple password authentication.</p>
<h2 id="heading-about-2fa-and-mfa">About 2FA and MFA</h2>
<h3 id="heading-weaknesses-of-simple-passwords">Weaknesses of Simple Passwords</h3>
<p>Passwords are our most common security verification method, but simple password systems have many flaws. First, the strength of a password largely depends on the user. If a user sets a simple password (such as 123456, or using personal information like birthdays), it can be easily guessed and breached by hackers. Secondly, even if a user sets a strong password, it cannot completely avoid threats like <a target="_blank" href="https://en.wikipedia.org/wiki/Phishing">Website Phishing</a> or <a target="_blank" href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack">Man-in-the-middle (MITM) attacks</a>, as these often deceive users into revealing their passwords. Lastly, many users often reuse the same password across different websites, putting other accounts at risk if these passwords are leaked on any site.</p>
<h3 id="heading-the-importance-of-identity-verification">The Importance of Identity Verification</h3>
<p>Advanced identity verification methods, such as two-factor authentication (2FA) and multi-factor authentication (MFA), can significantly reduce the risk of password breaches. Even if hackers know the password, they cannot pass the second or additional layers of verification, thus protecting the user's account.</p>
<p>These advanced verification methods usually require users to provide three types of information:</p>
<p>Something you have (e.g., a mobile device to receive a verification code) Something you know (e.g., a password) Or something you are (e.g., a fingerprint or facial recognition) to confirm their identity. In this way, even if hackers know one type of proof, they cannot easily obtain the others, greatly increasing account security.</p>
<h3 id="heading-the-concept-of-2fa-and-mfa">The Concept of 2FA and MFA</h3>
<p>Therefore, in recent years, internet security has gradually adopted more robust verification methods, known as two-factor authentication (2FA) and multi-factor authentication (MFA).</p>
<p>2FA, or two-factor authentication, means adding a second layer of security verification to the traditional password authentication during the login process, such as SMS codes, email verification, fingerprint recognition, etc., greatly enhancing account security.</p>
<p>MFA, or multi-factor authentication, adds two or more verification methods during the verification process. These methods may include passwords, biometric recognition, behavioral characteristics, etc.</p>
<p>By using these two verification methods, we can effectively enhance website security, preventing unauthorized access and data theft.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1701371412480/0fb803d8-0cd2-4aaf-9128-e0f87471f06b.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-what-is-2fa-two-factor-authentication">What is 2FA (Two-Factor Authentication)?</h2>
<p>Two-factor authentication (2FA) is a method of enhanced security verification that requires users to provide two different forms of identity proof for authentication. These two proofs typically come from the following three categories: information the user knows (such as a password), an object the user possesses (such as a mobile phone receiving a verification code), and the user's physical characteristics (such as fingerprints or facial recognition).</p>
<h3 id="heading-how-2fa-works">How 2FA Works</h3>
<p>When a user attempts to log in or perform certain sensitive operations, the system first asks them to provide one form of identity proof, usually a password. Then, the system requests a second form of proof, such as a verification code sent via SMS to the user's mobile phone, or data from a biometric device (like a fingerprint scanner). Only when both forms of identity proof are correct will the system authenticate the user.</p>
<h3 id="heading-common-2fa-verification-methods">Common 2FA Verification Methods</h3>
<ol>
<li><p><strong>SMS Verification</strong>: The system sends a verification code to the user's mobile phone, which the user must enter on the system to proceed.</p>
</li>
<li><p><strong>Email Verification</strong>: Similar to SMS verification, but the code is sent to the user's email.</p>
</li>
<li><p><strong>Biometrics</strong>: Includes fingerprint recognition, facial recognition, or retina scanning.</p>
</li>
<li><p><strong>Hardware Security Token</strong>: Such as YubiKey or Google Titan, where users need to insert these physical keys into a computer or contact them with a mobile phone via NFC for identity verification.</p>
</li>
</ol>
<h3 id="heading-advantages-of-2fa">Advantages of 2FA</h3>
<ol>
<li><p><strong>Enhanced Security</strong>: As it requires two forms of identity proof, even if one is known to hackers, they cannot proceed, thus enhancing account security.</p>
</li>
<li><p><strong>Reduced Identity Theft</strong>: Even if the password is cracked by hackers, they cannot mimic the user's biometrics or obtain physical security keys, significantly reducing the risk of identity theft.</p>
</li>
</ol>
<h3 id="heading-disadvantages-of-2fa">Disadvantages of 2FA</h3>
<ol>
<li><p><strong>Reduced Convenience</strong>: Users need to complete two verifications, which may be troublesome, especially in situations requiring frequent logins.</p>
</li>
<li><p><strong>Additional Device Needed</strong>: Some 2FA methods (such as biometrics or physical security keys) may require specific devices, potentially increasing usage costs.</p>
</li>
</ol>
<h2 id="heading-what-is-mfa-multi-factor-authentication">What is MFA (Multi-Factor Authentication)?</h2>
<p>Multi-factor authentication (MFA) requires users to provide more than two forms of identity proof to enhance account security. These proofs still originate from the following three categories: information the user knows (such as a password), an object the user possesses (such as a mobile phone or security key receiving a verification code), and the user's physical characteristics (such as fingerprints or facial recognition).</p>
<h3 id="heading-how-mfa-works">How MFA Works</h3>
<p>Similar to 2FA, when a user attempts to log in or perform sensitive operations, the system asks them to sequentially provide multiple forms of identity proof. Each proof must pass before the system authenticates the user. By requiring users to provide more types of identity proof, MFA offers multiple layers of security.</p>
<h3 id="heading-common-mfa-verification-methods">Common MFA Verification Methods</h3>
<ol>
<li><p><strong>SMS Verification + Password + Biometrics</strong>: A very common MFA method where users need to provide these three proofs to log in.</p>
</li>
<li><p><strong>Hardware Security Token + Password + Biometrics</strong>: This method is often used in high-security environments, such as government or military facilities.</p>
</li>
</ol>
<h3 id="heading-advantages-of-mfa">Advantages of MFA</h3>
<ol>
<li><p><strong>More Security</strong>: As it requires multiple forms of identity proof, even if hackers obtain one or two proofs, they cannot pass all verifications, greatly enhancing account security.</p>
</li>
<li><p><strong>More Comprehensive Protection</strong>: MFA, by combining various forms of identity proof, can combat different threats, providing more comprehensive protection.</p>
</li>
</ol>
<h3 id="heading-disadvantages-of-mfa">Disadvantages of MFA</h3>
<ol>
<li><p><strong>Reduced Convenience</strong>: Similar to 2FA, MFA requires users to complete multiple verifications, which may make the login process cumbersome.</p>
</li>
<li><p><strong>Additional Device Needed</strong>: Some MFA methods may require specific devices, such as biometric devices or physical security keys, potentially increasing implementation costs.</p>
</li>
</ol>
<h2 id="heading-does-my-website-need-2fa-or-mfa">Does My Website Need 2FA or MFA?</h2>
<h3 id="heading-when-to-use-2fa-or-mfa">When to Use 2FA or MFA</h3>
<p>If your website stores or processes sensitive data, such as personal information, credit card details, or other data that can be maliciously used, you should consider using 2FA or MFA. Especially in the current climate of rampant cyber attacks, using advanced verification methods to protect your website and your users is essential.</p>
<h3 id="heading-2fa-and-mfa-applications-on-different-websites">2FA and MFA Applications on Different Websites</h3>
<p>Various types of websites can benefit from 2FA or MFA. For example, e-commerce sites can use 2FA or MFA to protect customer payment information; social networking sites can use it to prevent account theft; medical websites can use it to ensure patient medical records are not accessed by unauthorized individuals.</p>
<h3 id="heading-how-to-implement-2fa-mfa-on-my-website">How to Implement 2FA, MFA on My Website</h3>
<p>Setting up and implementing 2FA or MFA may require professional technical knowledge. Fortunately, many third-party services, such as Google Authenticator, Authy, or Duo Security, offer easy-to-implement solutions. You can choose the right service to implement 2FA or MFA based on your needs and budget.</p>
<p>2FA and MFA play a key role in enhancing website security. Although they may reduce convenience, it is worth it compared to protecting user information security.</p>
<p>Regardless of your business size or website scale, its security should be taken seriously. If you want to learn how to implement 2FA, MFA on your website, or if you plan to build a new website and value its security, you are very welcome to consult with us. <a target="_blank" href="https://uniauth.com/">UniAuth</a> and <a target="_blank" href="https://lyrasoft.net/en/">LYRASOFT</a> has many years of experience in enterprise-level website development and can build a strong and complete website platform for you.</p>
]]></content:encoded></item><item><title><![CDATA[[Secure 101] Is It Really Safe to Change Passwords Every 90 Days or Regularly?]]></title><description><![CDATA[Traditional Idea: Users Should Change Passwords Frequently
In the digital world, protecting personal and corporate information security is a crucial aspect of our daily lives. Over the years, corporate security policies have often advised us to regul...]]></description><link>https://blog.uniauth.com/is-it-really-safe-to-change-passwords-regularly</link><guid isPermaLink="true">https://blog.uniauth.com/is-it-really-safe-to-change-passwords-regularly</guid><category><![CDATA[passwords]]></category><category><![CDATA[Passwordless]]></category><category><![CDATA[2FA]]></category><category><![CDATA[MFA]]></category><category><![CDATA[Two-factor authentication (2FA) ]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Simon Asika]]></dc:creator><pubDate>Mon, 27 Nov 2023 10:22:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1701453252938/8972ed3a-96a6-4fa5-b04f-9525d0b3462a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-traditional-idea-users-should-change-passwords-frequently"><strong>Traditional Idea: Users Should Change Passwords</strong> Frequently</h2>
<p>In the digital world, protecting personal and corporate information security is a crucial aspect of our daily lives. Over the years, corporate security policies have often advised us to regularly change passwords, every 60 to 90 days, to ensure the safety of our online accounts. This concept believes that regularly changing passwords can prevent long-term unauthorized use of our accounts. However, this practice has some issues in today's security environment.</p>
<h3 id="heading-problem-of-frequently-changing-passwords"><strong>Problem of Frequently Changing Passwords</strong></h3>
<p>Frequent password changes lead users to choose simple, easy-to-remember passwords or to make minor modifications to existing ones, such as adding a number at the end or slightly changing the order of letters. In such cases, even with regular password changes, security is greatly reduced as simple or slightly altered passwords are easier to crack.</p>
<p>Moreover, to remember different passwords, users might write them down, increasing the risk of severe password leakage. Some might prepare 3-4 sets of passwords to rotate, which defeats the purpose of changing passwords.</p>
<h3 id="heading-the-burden-on-corporate-organizations"><strong>The Burden on Corporate Organizations</strong></h3>
<p>Often, corporate security policies are designed just to comply with legal or audit requirements without considering practical operation. When the password change cycle comes around in large corporations, there can be a huge spike in password change requests, slightly impacting work productivity for that week.</p>
<p>Also, systems that lock accounts after multiple incorrect attempts can lead to a massive influx of help requests to the IT department at the start of the password change cycle, creating additional management issues for the organization.</p>
<h2 id="heading-new-idea-1-strong-passwords"><strong>New Idea 1: Strong Passwords</strong></h2>
<p>In recent years, the cybersecurity community has begun to question whether forcing users to regularly change passwords truly benefits information security. In 2017, the National Institute of Standards and Technology (NIST) in the USA advised against mandatory regular password changes. Instead, NIST recommends changing passwords only if they are known to be stolen and suggests using 'strong passwords' instead of frequently changing them.</p>
<p>A 'strong password' is hard to crack, typically consisting of 12 or more characters (some organizations require 16 or more), including uppercase and lowercase letters, numbers, and special symbols. A strong password should avoid any words found in the dictionary, personal information (like birthdays or names), or common password patterns (like <code>123456</code> or <code>abcdef</code>). For example, <code>Pc29_hJ/EfuZ*3ao</code> is a 16-character strong password.</p>
<p>By increasing the length and complexity of passwords, the time and resources needed to crack them are significantly increased, thus enhancing account security. Enterprises can consider using Single Sign-On (SSO) where a central employee system manages all employee passwords to meet the standards.</p>
<h3 id="heading-password-managers"><strong>Password Managers</strong></h3>
<p>Another approach within organizations is the introduction of password managers like 1Password, Lastpass, or Passpack. These managers facilitate the management of multiple strong passwords and prevent users from writing down passwords. While there are concerns about password manager breaches, the general consensus is that the risk of content leakage from managers is not as high as using the same password across multiple sites, which could lead to a breach on one site affecting all.</p>
<h2 id="heading-new-idea-2-two-factor-2fa-or-multi-factor-authentication-mfa"><strong>New Idea 2: Two-Factor (2FA) or Multi-Factor Authentication (MFA)</strong></h2>
<p>In some cases, two-factor authentication (2FA) can be more effective and address concerns about password manager leaks. 2FA requires two forms of proof to confirm identity, such as a password (knowledge) and a mobile phone (possession), or a fingerprint (biometric). Thus, even if a password is stolen, the thief cannot truly access the account.</p>
<p>For more information on 2FA, please see: <a target="_blank" href="https://blog.uniauth.com/what-are-2fa-and-mfa">What are 2FA and MFA, Does my WebSite Need This?</a></p>
<h2 id="heading-new-idea-3-passwordless-authentication"><strong>New Idea 3: Passwordless Authentication</strong></h2>
<p>Widespread passwordless authentication methods include mobile app scanning, fingerprint or facial recognition, OAuth, or third-party authentication. The authentication methods used in 2FA and MFA, such as biometrics or USB keys, can also serve as primary authentication methods.</p>
<p>The main concept of passwordless is that by using an entity that has already authenticated your identity (such as a website, organization, or mobile device), this authentication is granted to another software or website that requires login, thus confirming your identity without re-entering username and password.</p>
<p>Common passwordless strategies include QRCode scanning or app scanning for login.</p>
<h2 id="heading-conclusion-enterprises-should-rethink-password-management-strategies"><strong>Conclusion: Enterprises Should Rethink Password Management Strategies</strong></h2>
<p>As cybersecurity concepts evolve, enterprises need to rethink their existing password management strategies. Over-frequent password changes are not a silver bullet for information security. Instead, we should focus on creating strong passwords and applying two-factor authentication when appropriate. Such strategies can ensure our online safety while reducing the burden on users.</p>
<p><a target="_blank" href="https://uniauth.com/">UniAuth</a> and <a target="_blank" href="https://lyrasoft.net/en/">LYRASOFT</a> has extensive experience in website backend development and can implement systems such as SSO, OAuth, 2FA, MFA for enterprises. If your business has related needs, please feel free to contact us.</p>
]]></content:encoded></item><item><title><![CDATA[What is Secure Remote Password (SRP) and How to use it to protect users' passwords.]]></title><description><![CDATA[Introduction
Secure Remote Password (SRP) protocol is a method of secure authentication designed to safely verify a user's credentials without transmitting the password over the network.
Unlike traditional password hashes, which rely on a password be...]]></description><link>https://blog.uniauth.com/what-is-secure-remote-password</link><guid isPermaLink="true">https://blog.uniauth.com/what-is-secure-remote-password</guid><category><![CDATA[SRP]]></category><category><![CDATA[Security]]></category><category><![CDATA[passwords]]></category><category><![CDATA[Passwordless]]></category><dc:creator><![CDATA[Simon Asika]]></dc:creator><pubDate>Sun, 26 Nov 2023 07:40:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1700984703498/b022a28f-4203-4abc-8c61-2d4633bde876.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>Secure Remote Password (SRP) protocol is a method of secure authentication designed to safely verify a user's credentials without transmitting the password over the network.</p>
<p>Unlike traditional password hashes, which rely on a password being sent to the server and then compared to a stored hash, SRP will never transmit or store a user's password on the server, significantly reducing the risk of interception or server compromise. The benefits are that it stops different types of attacks like MITM (man-in-the-middle) attacks, doesn't need a password change if user data leaks, and lets both the user and server confirm each other's identity.</p>
<p>Major companies like Apple and 1Password have adopted SRP as part of their authentication mechanisms. Apple, for instance, has <a target="_blank" href="https://support.apple.com/guide/security/sec3e341e75d/web">implemented SRP in its iCloud Keychain</a> to securely synchronize passwords across devices without exposing them. Similarly, 1Password uses the user's master password and the secret to encrypt data, and both the password and secret <a target="_blank" href="https://blog.1password.com/developers-how-we-use-srp-and-you-can-too/">use SRP to authenticate accounts</a> and ensure that they won't transmit to the server.</p>
<h2 id="heading-about-this-article">About This Article</h2>
<p>This article aims to explain each step of <a target="_blank" href="https://datatracker.ietf.org/doc/html/rfc5054">SRP-6a</a> and provides a combined overview of RFC-5054 and RFC-2945. It also maps each calculation formula in the variable introduction and the sample code later in the article. This will be particularly helpful for developers who are new to SRP and want to understand how it's implemented in the RFCs, ensuring they can follow every calculation step mentioned.</p>
<p>Not all open-source packages follow the RFC standards completely, which means some may not work well with others. This article strictly follows SRP-6a, using the implementation in <a target="_blank" href="https://github.com/windwalker-io/srp">windwalker/srp</a> as a model. By following this example, your implementation should easily work with other packages that are fully RFC-compliant.</p>
<p>If you are interested in finding more packages that are fully implemented SRP-6a, see this <a target="_blank" href="https://github.com/secure-remote-password/implementations">SRP implementations list</a>.</p>
<h2 id="heading-the-srp-flow">The SRP Flow</h2>
<p>The definitions and processes of SRP-6a are dispersed in <a target="_blank" href="https://datatracker.ietf.org/doc/html/rfc2945">RFC 2945</a> and <a target="_blank" href="https://datatracker.ietf.org/doc/html/rfc5054">RFC 5054</a>; this is an attempt to integrate them for an overview. Please follow strictly to the RFC-specified procedures without custom modification, and do not transmit any variables unnecessarily to avoid security breaches.</p>
<h3 id="heading-definition">Definition</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Variable</td><td>Name</td><td>Send</td><td>Calc</td></tr>
</thead>
<tbody>
<tr>
<td><code>I</code>, <code>identity</code></td><td>The main identity (username or email).</td><td>C=&gt;S</td><td></td></tr>
<tr>
<td><code>N</code></td><td>A large safe prime, All arithmetic is done modulo N.</td><td>X</td><td></td></tr>
<tr>
<td><code>g</code></td><td>A generator modulo N</td><td>X</td><td></td></tr>
<tr>
<td><code>k</code></td><td>Multiplier parameter</td><td>X</td><td><code>SHA1(N ‖ PAD(g))</code></td></tr>
<tr>
<td><code>s</code></td><td>The user salt.</td><td>C&lt;=S</td><td><code>random()</code></td></tr>
<tr>
<td><code>v</code></td><td>Password Verifier</td><td>X</td><td><code>g^x % N</code></td></tr>
<tr>
<td><code>x</code></td><td>The hash of salt + identity + password.</td><td>X</td><td><code>SHA1(s ‖ SHA1(I ‖ ":" ‖ P))</code></td></tr>
<tr>
<td><code>a</code>, <code>b</code></td><td>Client &amp; server secret key</td><td>X</td><td><code>random()</code></td></tr>
<tr>
<td><code>A</code></td><td>Client public key</td><td>C=&gt;S</td><td><code>g^a % N</code></td></tr>
<tr>
<td><code>B</code></td><td>Server public key</td><td>C&lt;=S</td><td><code>k*v + g^b % N</code></td></tr>
<tr>
<td><code>u</code></td><td>The value of preventing attacker who learns a user's verifier</td><td>X</td><td><code>H(PAD(A) ‖ PAD(B))</code></td></tr>
<tr>
<td><code>S</code> (client)</td><td>Pre-master secret (The secure common session key)</td><td>X</td><td><code>(B - (k * g^x)) ^ (a + (u * x)) % N</code></td></tr>
<tr>
<td><code>S</code> (server)</td><td>Pre-master secret (The secure common session key)</td><td>X</td><td><code>(A * v^u) ^ b % N</code></td></tr>
<tr>
<td><code>K</code></td><td>The session key hash for used to generate M</td><td>X</td><td><code>H(S)</code></td></tr>
<tr>
<td><code>M1</code></td><td>Evidence message 1, To verify both sides generated the same session key.</td><td>C=&gt;S</td><td><code>H(H(N) XOR H(g) ‖ H(U) ‖ s ‖ A ‖ B ‖ K)</code></td></tr>
<tr>
<td><code>M2</code></td><td>Evidence message 2, To verify both sides generated the same session key.</td><td>C&lt;=S</td><td><code>H(A ‖ M ‖ K)</code></td></tr>
</tbody>
</table>
</div><h3 id="heading-registration">Registration</h3>
<p><img src="https://github.com/windwalker-io/srp/assets/1639206/9cfe047e-6baa-4208-bfde-59cbe501303a" alt="Registration flow, img via windwalker/srp" /></p>
<p>When an app (web/mobile) start the registration flow, it may display a <code>identity</code> (<code>I</code>) (username or email) and <code>password</code> (<code>P</code>) field to user. They entered their username and password and then clicked the register button. The SRP client will generate a random <code>salt</code> (<code>s</code>), and a password <code>verifier</code> (<code>v</code>) which is generated from salt, identity and password.</p>
<p>Then app will send only the <code>salt</code>, <code>verifier</code> and <code>identity</code> to the server and do not send <code>password</code>. It is a protocol violation and security bug if the raw password is accidently transmitted to the server even if it is ignored by the server.</p>
<p>You can save the user info and <code>salt</code>, <code>verifier</code> to DB when server receives the registration request. It is optional if you want to encrypt the salt and verifier before saving, make sure you encrypt it by a key that is only known by server.</p>
<h3 id="heading-login">Login</h3>
<p><img src="https://github.com/windwalker-io/srp/assets/1639206/a01b4d82-2c28-4d95-8615-dca38408c2d5" alt="Login flow, img via windwalker/srp" /></p>
<h4 id="heading-hello-and-server-step1">Hello and Server step1</h4>
<p>When a user starts the login process, they may enter their identity and password on form fields, and click the login button. The SRP client will send a Hello request with <code>identity</code> to server. The server should check user exists by this identity, and get <code>salt</code> and <code>verifier</code> from user data. Next, server will generate a random private <code>b</code> and a public <code>B</code>, and remember them by DB, session or cache storage that we will need them in the further steps, then, return the <code>salt</code>, <code>B</code> back to client (Server Hello). This process is similar to a handshake, to create a connecting session for both sides.</p>
<blockquote>
<p>Some package calls the client Hello as <code>challenge</code> action, and the <code>B</code> is the server challenge value.</p>
</blockquote>
<h4 id="heading-client-steps-1-amp-2">Client steps 1 &amp; 2</h4>
<p>After receiving the <code>B</code> and <code>salt</code>, Client runs step 1 to generate <code>a</code> and <code>A</code>, and then, runs step2 to use all of the above values to generate a client proof <code>M1</code>. It will be sent to server with <code>A</code> (authenticate action). Server side also use all the generated values to generate a <code>M1</code> and compare it. If compared failure, server will report an error, and if compared success, server will generate a server proof <code>M2</code> and back to client. To this step, the authenticate actions are done, you can simply redirect user to the login success page.</p>
<p>There is an optional Client step3 is that you can verify the <code>M2</code> to authority server is trusted and make sure both sides generate the same session key (<code>S</code>). If you have done this step3, it means you completed the authenticate handshake and did a two-way authentication. If you want to run the step3 to complete all the processes, you can redirect user after step3 done.</p>
<h4 id="heading-about-the-s-and-m">About the <code>S</code> and <code>M</code></h4>
<p>When client and server generating <code>M</code>, they will both generate a premaster secret (<code>S</code>). The <code>S</code> should be same, even if the 2 sides did not send <code>S</code> to another. The <code>M1</code> and <code>M2</code> is a verifier to make sure both side have a same <code>S</code>. So, <code>S</code> can be a trusted session key or encryption key if you want to do some other cryptography behavior in the future.</p>
<h2 id="heading-the-example-code">The Example Code</h2>
<p>Here is a pseudo-code to show how SRP server-side and client-side cross works.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> server = SRPServer.create();
<span class="hljs-keyword">const</span> client = SRPClient.create();

<span class="hljs-comment">// Register</span>
<span class="hljs-keyword">const</span> identity = <span class="hljs-string">'...'</span>;
<span class="hljs-keyword">const</span> password = <span class="hljs-string">'...'</span>;

<span class="hljs-comment">// Register: generate new salt &amp; verifier</span>

<span class="hljs-comment">// random()</span>
<span class="hljs-keyword">const</span> salt = client.generateSalt();
<span class="hljs-comment">// (SHA(s | SHA(I | `:` | P)))</span>
<span class="hljs-keyword">const</span> x = client.generateX(salt, identity, password);
<span class="hljs-comment">// (g^x % N)</span>
<span class="hljs-keyword">const</span> verifier = client.generateVerifier(x);


<span class="hljs-comment">// Send salt and verifier to Server store</span>


<span class="hljs-comment">// Login start</span>
<span class="hljs-comment">// AJAX:hello?{identity} - Server step (1)</span>
<span class="hljs-comment">// salt &amp; verifier has already stored on user data, server can get it from DB</span>
<span class="hljs-comment">// b &amp; B must remember on session, we will use it at following steps.</span>

<span class="hljs-comment">// random()</span>
<span class="hljs-keyword">const</span> b = server.generateRandomSecret();
<span class="hljs-comment">// ((k*v + g^b) % N)</span>
<span class="hljs-keyword">const</span> B = server.generateB(b, verifier);


<span class="hljs-comment">// Server returns B &amp; salt to client</span>


<span class="hljs-comment">// Client step (1)</span>

<span class="hljs-comment">// random()</span>
<span class="hljs-keyword">const</span> a = client.generateRandomSecret();
<span class="hljs-comment">// (g^a % N)</span>
<span class="hljs-keyword">const</span> A = client.generateA(a);
<span class="hljs-comment">// (SHA(s | SHA(I | `:` | P)))</span>
<span class="hljs-keyword">const</span> x = client.generateX(salt, identity, password);


<span class="hljs-comment">// Client step (2)</span>

<span class="hljs-comment">// H(PAD(A) | PAD(B))</span>
<span class="hljs-keyword">const</span> u = client.generateU(A, B);
<span class="hljs-comment">// ((B - (k * g^x)) ^ (a + (u * x)) % N)</span>
<span class="hljs-keyword">const</span> S = client.generateS(a, B, x, u);
<span class="hljs-comment">// H(S)</span>
<span class="hljs-keyword">const</span> K = client.hash(S);
<span class="hljs-comment">// H(H(N) xor H(g), H(I), s, A, B, K)</span>
<span class="hljs-keyword">const</span> M1Client = client.generateM1(identity, salt, A, B, K);


<span class="hljs-comment">// AJAX:authenticate?{identity,A,M1} - Server step (2)</span>
<span class="hljs-comment">// Send identity &amp; A &amp; M1 to server and compare it.</span>
<span class="hljs-comment">// The salt &amp; verifier stored on user data, get it from DB.</span>
<span class="hljs-comment">// The b, B stored in session state, get and clear them.</span>

<span class="hljs-comment">// H(PAD(A) | PAD(B))</span>
<span class="hljs-keyword">const</span> u = server.generateU(A, B);
<span class="hljs-comment">// ((A * v^u) ^ b % N)</span>
<span class="hljs-keyword">const</span> S = server.generateS(A, b, verifier, u);
<span class="hljs-comment">// H(S)</span>
<span class="hljs-keyword">const</span> K = server.hash(S);
<span class="hljs-comment">// H(H(N) xor H(g), H(I), s, A, B, K)</span>
<span class="hljs-keyword">const</span> M1Server = server.generateM1(identity, salt, A, B, K);

<span class="hljs-comment">// Do compare</span>
<span class="hljs-keyword">if</span> (!crypto.timeingSafeEquals(M1Client, M1Server)) {
  <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Invalid client session proof.'</span>);
}

<span class="hljs-comment">// Now create a M2 as server proof</span>
<span class="hljs-comment">// H(A | M | K)</span>
<span class="hljs-keyword">const</span> M2Server = server.generateM2(A, M1Server, K);

<span class="hljs-comment">// Server returns M2 to Client</span>
<span class="hljs-comment">// Client step (3) (optional)</span>

<span class="hljs-comment">// H(A | M | K)</span>
<span class="hljs-keyword">const</span> M2Client = client.generateM2(A, M1Client, K);


<span class="hljs-comment">// Do compare</span>
<span class="hljs-keyword">if</span> (!crypto.timeingSafeEquals(M2Client, M2Server)) {
  <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(<span class="hljs-string">'Invalid server session proof.'</span>);
}

<span class="hljs-comment">// If all passed, should not throw any exceptions.</span>
</code></pre>
<h2 id="heading-some-important-notes">Some Important Notes</h2>
<ul>
<li><p>You don't need to use AJAX to implement SRP flow. You can simply use form post to do all the steps. For example, you may separate username and password into 2 steps on your website, and store values in hidden inputs. Make sure you stored <code>a</code> and <code>b</code> in your browser and server cache that can use them cross steps and do not accidently send them to remote side.</p>
</li>
<li><p>The <code>verifier</code> is generated from identity and password, which means you must re-create a new verifier to replace old one if user changes either of <code>identity</code> or <code>password</code>.</p>
</li>
<li><p>Always make sure you don't send any unnecessary values to each side, even if server or client ignore them, it is considered as a protocol violation and security bug. Also, the <a target="_blank" href="https://en.wikipedia.org/wiki/Man-in-the-middle_attack">MITM attacker</a> can use these sensitive data.</p>
</li>
<li><p>Always clear values when restart an authenticate process. Generally, you can reload page so that all values and JS object will be reset. If you are developing a SPA app, wrap whole process in a function and do not cache values to object properties, and if you are using an SRP library, always re-create the library objects when user retries.</p>
</li>
<li><p>SRP should not replace HTTPS, you should always use SSL/TLS on your app and enable the Cookies HttpOnly and secure settings.</p>
</li>
</ul>
<hr />
<h2 id="heading-related-links">Related Links</h2>
<ul>
<li><p><a target="_blank" href="https://github.com/simbo1905/thinbus-srp-npm">thinbus-srp</a> (JS SRP implementation)</p>
</li>
<li><p><a target="_blank" href="https://github.com/artisansdk/srp">artisansdk/srp</a> (PHP/JS SRP implementation)</p>
</li>
<li><p><a target="_blank" href="https://github.com/windwalker-io/srp">windwalker/srp</a> (PHP/JS SRP implementation)</p>
</li>
<li><p><a target="_blank" href="https://github.com/secure-remote-password/implementations">More SRP implementation List</a></p>
</li>
</ul>
<p>Images via <a target="_blank" href="https://github.com/windwalker-io/srp">windwalker/srp</a></p>
]]></content:encoded></item></channel></rss>