MdpUploadSigningKeys.cs 1.0 KB

123456789101112131415161718192021222324252627
  1. using System.Security.Cryptography;
  2. using System.Text;
  3. namespace Admin.NET.Plugin.AiDOP.DataPlatform.UnifiedIngress;
  4. internal static class MdpUploadSigningKeys
  5. {
  6. internal const string Reference = "managed:tenant-upload:v1";
  7. // Provision once per environment; all API replicas use the same private signing root.
  8. internal static byte[] Derive(string accessKey)
  9. {
  10. var path = Environment.GetEnvironmentVariable("MDP_INGRESS_ISSUER_KEY_FILE");
  11. if (string.IsNullOrWhiteSpace(path))
  12. path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".aidop", "mdp-ingress-issuer-v1.key");
  13. var root = File.ReadAllBytes(path);
  14. try
  15. {
  16. if (root.Length != 32) throw new InvalidOperationException("INGRESS_ISSUER_KEY_UNAVAILABLE");
  17. return HMACSHA256.HashData(root, Encoding.UTF8.GetBytes(Reference + "/" + accessKey));
  18. }
  19. finally
  20. {
  21. CryptographicOperations.ZeroMemory(root);
  22. }
  23. }
  24. }