This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from zkhcohen/pkce-auth
Pkce auth
- Loading branch information
Showing
311 changed files
with
10,208 additions
and
7,569 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
CHANGE LOG: | ||
|
||
Beta 2.0: Improved performance. Removed 500 album restriction. Added automatic prompt to re-authenticate if computer resumes from sleep. | ||
Beta 2.0.2: Fixed error log spam. | ||
Release 2.0: Improved performance. Removed 500 album restriction. Added automatic prompt to re-authenticate if computer resumes from sleep. | ||
Release 2.0.2: Fixed error log spam. | ||
Beta 3.1: Upgraded all API methods to 6.x.x spec. Implemented PKCE auth method with token persistence and automatic renewal. General speed improvements. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using System; | ||
using System.Xml; | ||
using System.Security.Cryptography; | ||
using System.Security.Cryptography.Xml; | ||
|
||
namespace MusicBeePlugin | ||
{ | ||
public partial class Plugin | ||
{ | ||
public static void Encrypt(XmlDocument Doc, string ElementToEncrypt, string EncryptionElementID, RSA Alg, string KeyName) | ||
{ | ||
if (Doc == null) | ||
throw new ArgumentNullException("Doc"); | ||
if (ElementToEncrypt == null) | ||
throw new ArgumentNullException("ElementToEncrypt"); | ||
if (EncryptionElementID == null) | ||
throw new ArgumentNullException("EncryptionElementID"); | ||
if (Alg == null) | ||
throw new ArgumentNullException("Alg"); | ||
if (KeyName == null) | ||
throw new ArgumentNullException("KeyName"); | ||
|
||
XmlElement elementToEncrypt = Doc.GetElementsByTagName(ElementToEncrypt)[0] as XmlElement; | ||
|
||
if (elementToEncrypt == null) | ||
{ | ||
throw new XmlException("The specified element was not found"); | ||
} | ||
Aes sessionKey = null; | ||
|
||
try | ||
{ | ||
EncryptedXml eXml = new EncryptedXml(); | ||
EncryptedData edElement = new EncryptedData(); | ||
EncryptedKey ek = new EncryptedKey(); | ||
DataReference dRef = new DataReference(); | ||
KeyInfoName kin = new KeyInfoName(); | ||
|
||
sessionKey = Aes.Create(); | ||
|
||
byte[] encryptedElement = eXml.EncryptData(elementToEncrypt, sessionKey, false); | ||
|
||
edElement.Type = EncryptedXml.XmlEncElementUrl; | ||
edElement.Id = EncryptionElementID; | ||
edElement.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncAES256Url); | ||
|
||
byte[] encryptedKey = EncryptedXml.EncryptKey(sessionKey.Key, Alg, false); | ||
|
||
ek.CipherData = new CipherData(encryptedKey); | ||
ek.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncRSA15Url); | ||
dRef.Uri = "#" + EncryptionElementID; | ||
ek.AddReference(dRef); | ||
edElement.KeyInfo.AddClause(new KeyInfoEncryptedKey(ek)); | ||
kin.Value = KeyName; | ||
ek.KeyInfo.AddClause(kin); | ||
edElement.CipherData.CipherValue = encryptedElement; | ||
|
||
EncryptedXml.ReplaceElement(elementToEncrypt, edElement, false); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw e; | ||
} | ||
finally | ||
{ | ||
if (sessionKey != null) | ||
{ | ||
sessionKey.Clear(); | ||
} | ||
} | ||
} | ||
|
||
public static void Decrypt(XmlDocument Doc, RSA Alg, string KeyName) | ||
{ | ||
if (Doc == null) | ||
throw new ArgumentNullException("Doc"); | ||
if (Alg == null) | ||
throw new ArgumentNullException("Alg"); | ||
if (KeyName == null) | ||
throw new ArgumentNullException("KeyName"); | ||
|
||
EncryptedXml exml = new EncryptedXml(Doc); | ||
|
||
exml.AddKeyNameMapping(KeyName, Alg); | ||
exml.DecryptDocument(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.