Skip to content

[Neo Wallet Fix] Add cert import exception#3279

Merged
NGDAdmin merged 11 commits intoneo-project:masterfrom
Jim8y:cert-error-macos
May 31, 2024
Merged

[Neo Wallet Fix] Add cert import exception#3279
NGDAdmin merged 11 commits intoneo-project:masterfrom
Jim8y:cert-error-macos

Conversation

@Jim8y
Copy link
Contributor

@Jim8y Jim8y commented May 27, 2024

Description

Dotnet has no implementation of ExportParameters for ECdsa, thus causing the Import method fail.

Fixes # (issue)

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Updated the Unit test of TestImportCert in UT_NEP6Wallet.cs

  • TestImportCert

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y Jim8y requested a review from a team May 27, 2024 01:17

public override WalletAccount Import(X509Certificate2 cert)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be implemented with 3rd-party libraries for OSX?

Copy link
Contributor Author

@Jim8y Jim8y May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have tried, cant extract the private key. nothing in the ecdsa or cert is implementated on the macos that can help.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenSSL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary, no one use this. exception is fine already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If openssl is installed on the machine and configured right. dotnet will use it automatically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if it works with openssl installed, with this condition it wont never work

shargon
shargon previously approved these changes May 28, 2024
@Jim8y Jim8y requested a review from a team May 28, 2024 08:08
@Jim8y
Copy link
Contributor Author

Jim8y commented May 28, 2024

time to fix the random error:

Warning: D:\a\neo\neo\src\Neo\SmartContract\ApplicationEngine.cs(256,27): warning CS0618: 'ApplicationEngine.GasConsumed' is obsolete: 'This property is deprecated. Use FeeConsumed instead.' [D:\a\neo\neo\src\Neo\Neo.csproj::TargetFramework=net8.0]
C:\Program Files\dotnet\sdk\8.0.300\Microsoft.Common.CurrentVersion.targets(2401,5): error MSB3248: Parameter "AssemblyFiles" has invalid value "D:\a\neo\neo\src\Neo\bin\Debug\net8.0\Neo.dll". The process cannot access the file 'D:\a\neo\neo\src\Neo\bin\Debug\net8.0\Neo.dll' because it is being used by another process. [D:\a\neo\neo\src\Plugins\RpcServer\RpcServer.csproj::TargetFramework=net8.0]
Neo -> D:\a\neo\neo\src\Neo\bin\Debug\net8.0\Neo.dll
Neo -> D:\a\neo\neo\src\Neo\bin\Debug\netstandard2.1\Neo.dll

cschuchardt88
cschuchardt88 previously approved these changes May 28, 2024
@cschuchardt88 cschuchardt88 dismissed their stale review May 28, 2024 14:06

No reason to have this PR. Tests were working fine as before. So that shows that this works on macos.

@Jim8y
Copy link
Contributor Author

Jim8y commented May 28, 2024

No reason to have this PR. Tests were working fine as before. So that shows that this works on macos.

What a disrespectful expression, feels like i am faking the issue:

Test method Neo.UnitTests.Wallets.NEP6.UT_NEP6Wallet.TestImportCert threw exception: 
Interop+AppleCrypto+AppleCFErrorCryptographicException: The operation couldn’t be completed. (OSStatus error -67738 - CSSM Exception: -2147415780 CSSMERR_CSP_INVALID_KEYATTR_MASK)
    at Interop.AppleCrypto.TrySecKeyCopyExternalRepresentation(SafeSecKeyRefHandle key, Byte[]& externalRepresentation)
   at System.Security.Cryptography.EccSecurityTransforms.TryExportDataKeyParameters(SecKeyPair keys, Boolean includePrivateParameters, ECParameters& ecParameters)
   at System.Security.Cryptography.EccSecurityTransforms.ExportParameters(Boolean includePrivateParameters, Int32 keySizeInBits)
   at Neo.Wallets.NEP6.NEP6Wallet.Import(X509Certificate2 cert) in /Users/jinghuiliao/git/neo/src/Neo/Wallets/NEP6/NEP6Wallet.cs:line 229
   at Neo.UnitTests.Wallets.NEP6.UT_NEP6Wallet.TestImportCert() in /Users/jinghuiliao/git/neo/tests/Neo.UnitTests/Wallets/NEP6/UT_NEP6Wallet.cs:line 305
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

@Jim8y
Copy link
Contributor Author

Jim8y commented May 28, 2024

@neo-project/core finally fixed with BouncyCastle

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same logic as?

public virtual WalletAccount Import(X509Certificate2 cert)
{
byte[] privateKey;
using (ECDsa ecdsa = cert.GetECDsaPrivateKey())
{
privateKey = ecdsa.ExportParameters(true).D;
}
WalletAccount account = CreateAccount(privateKey);
Array.Clear(privateKey, 0, privateKey.Length);
return account;
}

@cschuchardt88
Copy link
Member

cschuchardt88 commented May 29, 2024

What a disrespectful expression, feels like i am faking the issue:

Is this on your computer? Then does the tests work on github?

@shargon
Copy link
Member

shargon commented May 29, 2024

Use the same logic as?

public virtual WalletAccount Import(X509Certificate2 cert)
{
byte[] privateKey;
using (ECDsa ecdsa = cert.GetECDsaPrivateKey())
{
privateKey = ecdsa.ExportParameters(true).D;
}
WalletAccount account = CreateAccount(privateKey);
Array.Clear(privateKey, 0, privateKey.Length);
return account;
}

That's logic doesn't work in mac?

@cschuchardt88
Copy link
Member

That's logic doesn't work in mac?

It would have to be working. It is currently in the code right now. I think his computer isn't configured right.

@Jim8y Jim8y requested a review from a team May 30, 2024 00:31
@Jim8y Jim8y requested a review from a team May 30, 2024 03:37
@NGDAdmin NGDAdmin merged commit 2c0ce81 into neo-project:master May 31, 2024
@Jim8y Jim8y deleted the cert-error-macos branch June 14, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants