Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.PlatformNotSupportedException: 'Operation is not supported on this platform.' when upgrading ServiceStack to .netcore 2.0

We are using ServiceStack(.netcore) as our web services layer, in an open source project yet to go-live. We are planning to migrate to .netcore2.0. We downloaded servicestacks's master branch on Nov 17 from https://github.com/ServiceStack/ServiceStack for testing. But we are stuck due to the following exception, servicestack project is not starting up.

We did some research on this and found that .Net Core don't have the toXmlString() and fromXmlString method. Please see https://github.com/dotnet/core/issues/874 and https://github.com/dotnet/corefx/issues/23686.

Need help from the servicestack community.

$exception {System.PlatformNotSupportedException: Operation is not supported on this platform. at System.Security.Cryptography.RSA.FromXmlString(String xmlString) at ServiceStack.RsaUtils.ToPrivateRSAParameters(String privateKeyXml) in F:\ExpressBase\ExpressBase.Core\ServiceStack.Core\ServiceStack.Client\CryptUtils.cs:line 85 at ServiceStack.Auth.JwtAuthProviderReader.set_PrivateKeyXml(String value) in F:\ExpressBase\ExpressBase.Core\ServiceStack.Core\ServiceStack\Auth\JwtAuthProviderReader.cs:line 148 at ExpressBase.ServiceStack.AppHost.Configure(Container container) in F:\ExpressBase\ExpressBase.Core\ExpressBase.ServiceStack\Startup.cs:line 94 at ServiceStack.ServiceStackHost.Init() in F:\ExpressBase\ExpressBase.Core\ServiceStack.Core\ServiceStack\ServiceStackHost.cs:line 200 at ServiceStack.NetCoreAppHostExtensions.UseServiceStack(IApplicationBuilder app, AppHostBase appHost) in F:\ExpressBase\ExpressBase.Core\ServiceStack.Core\ServiceStack\AppHostBase.NetCore.cs:line 224 at ExpressBase.ServiceStack.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in F:\ExpressBase\ExpressBase.Core\ExpressBase.ServiceStack\Startup.cs:line 74} System.PlatformNotSupportedException

This is the line in our Startup.cs that is generating the Exception.

var jwtprovider = new MyJwtAuthProvider(AppSettings)
            {
                HashAlgorithm = "RS256",
                PrivateKeyXml = EbLiveSettings.PrivateKeyXml,
                PublicKeyXml = EbLiveSettings.PublicKeyXml,
                RequireSecureConnection = false,
                //EncryptPayload = true,
                CreatePayloadFilter = (payload, session) =>
                {
                    payload["sub"] = (session as CustomUserSession).UserAuthId;
                    payload["cid"] = (session as CustomUserSession).CId;
                    payload["uid"] = (session as CustomUserSession).Uid.ToString();
                    payload["wc"] = (session as CustomUserSession).WhichConsole;
                },
                ExpireTokensIn = TimeSpan.FromHours(10),
                ExpireRefreshTokensIn = TimeSpan.FromHours(12),
                PersistSession = true,
                SessionExpiry = TimeSpan.FromHours(12)
            };

The private and public key values are loaded from appsettings.json to EbLiveSettings.

The line in appsettings.json is

"JwtConfig": {
    "PublicKeyXml": "<RSAKeyValue><Modulus>ip...7BfGi98ObWqKnD8o4pv....JQklgmblCs=</Modulus><Exponent>AQAB</Exponent><P></P><Q></Q><DP></DP><DQ></DQ><InverseQ></InverseQ><D></D></RSAKeyValue>",
    "PrivateKeyXml": "<RSAKeyValue><Modulus>ip....lss7WqKnD8o4bKTp....IKbK2gaagCQ==</DP><DQ>BKOC....zlic+FQ==</DQ><InverseQ>JeIPWX....A==</InverseQ><D>iHU....cTrKeEGd</D></RSAKeyValue>"
  },
like image 656
Ahammed Unni V P Avatar asked Nov 20 '17 08:11

Ahammed Unni V P


1 Answers

Can you retry with the latest source code from master as I've restored some RSA polyfills for .NET Core.

like image 109
mythz Avatar answered Oct 13 '22 17:10

mythz