public bool TryGetSenderRecordData(out RecordData?recordData)
        {
            if (SenderRecordData == null || SenderRecordData.Length == 0)
            {
                recordData = default;
                return(false);
            }

            // validate that the signature is valid
            var signedCms = new SignedCms();

            try
            {
                signedCms.Decode(SenderRecordData);
                signedCms.CheckSignature(
                    new X509Certificate2Collection(ResourceLoader.AppleRootCA), true
                    );
            }
            catch
            {
                recordData = default;
                return(false);
            }

            recordData = PropertyListSerializer.Deserialize <RecordData>(signedCms.ContentInfo.Content);
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Writes an object of the specified type from the HTTP request using Apple's plist binary format.
        /// </summary>
        public static ValueTask <T> ReadFromPropertyListAsync <T>(this HttpRequest request) where T : class, new()
        {
            if (!request.ContentLength.HasValue || request.ContentLength > PropertyListSerializer.MaxPropertyListLength)
            {
                throw new HttpRequestException("Content length is too long.");
            }

            return(PropertyListSerializer.DeserializeAsync <T>(request.Body));
        }
Exemple #3
0
        /// <summary>
        /// Writes the specified object to the HTTP response in Apple's plist binary format.
        /// </summary>
        public static ValueTask WriteAsPropertyListAsync <T>(this HttpResponse response, T obj) where T : class
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            response.ContentType = "application/octet-stream";
            return(PropertyListSerializer.SerializeAsync(obj, response.Body));
        }