Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to generate a licence #19

Closed
tam481 opened this issue May 25, 2019 · 24 comments
Closed

Unable to generate a licence #19

tam481 opened this issue May 25, 2019 · 24 comments

Comments

@tam481
Copy link

tam481 commented May 25, 2019

Hello,
When running /run.sh /opt/BitBetter/.keys/cert.pfx user aa@bb.com aa@bb.com 12345679
I get the error message at the bottom: (Similar to issue #4)

I followed the instructions and installed dotnet add package Newtonsoft.Json --version 11.0.0 before running the build.sh

What am I doing wrong?

##Oops: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.

File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.GetSerializableMembers(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperties(Type type, MemberSerialization memberSerialization)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at bitwardenSelfLicensor.Program.GenerateUserLicense(X509Certificate2 cert, String corePath, String userName, String email, Guid userId, String key) in /opt/BitBetter/src/licenseGen/Program.cs:line 175
   at bitwardenSelfLicensor.Program.<>c__DisplayClass0_1.<Main>b__6() in /opt/BitBetter/src/licenseGen/Program.cs:line 75
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at bitwardenSelfLicensor.Program.Main(String[] args) in /opt/BitBetter/src/licenseGen/Program.cs:line 137

@JeffAlyanak
Copy link
Collaborator

What version of the dotnet-sdk did you install? It seems like it wants version 12.0.0 of Newtonsoft.Json.

@tam481
Copy link
Author

tam481 commented May 25, 2019

I installed "dotnet-sdk-2.1"

@tam481
Copy link
Author

tam481 commented May 25, 2019

running (dotnet --version)
Returns (2.1.700)

@JeffAlyanak
Copy link
Collaborator

JeffAlyanak commented May 26, 2019

And just to confirm, you ran the dotnet add package Newtonsoft.Json --version 11.0.0 command from within the /src/licenseGen/ directory before running the build script for the license generator?

Perhaps there's something different about your dotnet install or your environment that is causing it to look for version 12.0.0. You can try just adding that package and rebuilding.

@tam481
Copy link
Author

tam481 commented May 26, 2019

I did exactly as per your documentation.
I ran dotnet add package Newtonsoft.Json --version 11.0.0 inside both /src/licenseGen and /src/bitBetter

@tam481
Copy link
Author

tam481 commented May 26, 2019

This morning I tried dotnet add package Newtonsoft.Json --version 12.0.0 to no avail

@JeffAlyanak
Copy link
Collaborator

JeffAlyanak commented May 26, 2019

Can you please re-run the src/licenseGen/build.sh and post what it returns to the command line? Please use a multi-line code comment to keep it as readable as possible.

Can you also confirm the contents of your src/licenseGen/licenseGen.csproj file.

@tam481
Copy link
Author

tam481 commented May 26, 2019

Running src/licenceGen/build.sh returns the following:

/opt/BitBetter/src/licenseGen/licenseGen.csproj : warning NU1603: licenseGen depends on Newtonsoft.Json (>= 11.0.0) but Newtonsoft.Json 11.0.0 was not found. An approximate best match of Newtonsoft.Json 11.0.1 was resolved.
  Restore completed in 46.21 ms for /opt/BitBetter/src/licenseGen/licenseGen.csproj.
Microsoft (R) Build Engine version 16.1.76+g14b0a930a7 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

/opt/BitBetter/src/licenseGen/licenseGen.csproj : warning NU1603: licenseGen depends on Newtonsoft.Json (>= 11.0.0) but Newtonsoft.Json 11.0.0 was not found. An approximate best match of Newtonsoft.Json 11.0.1 was resolved.
  Restore completed in 39.9 ms for /opt/BitBetter/src/licenseGen/licenseGen.csproj.
/opt/BitBetter/src/licenseGen/licenseGen.csproj : warning NU1603: licenseGen depends on Newtonsoft.Json (>= 11.0.0) but Newtonsoft.Json 11.0.0 was not found. An approximate best match of Newtonsoft.Json 11.0.1 was resolved.
  licenseGen -> /opt/BitBetter/src/licenseGen/bin/Debug/netcoreapp2.0/licenseGen.dll
  licenseGen -> /opt/BitBetter/src/licenseGen/bin/Debug/netcoreapp2.0/publish/
Sending build context to Docker daemon  949.8kB
Step 1/3 : FROM bitbetter/api
 ---> 0fb112c12c9a
Step 2/3 : COPY bin/Debug/netcoreapp2.0/publish/* /app/
 ---> Using cache
 ---> 1de3b1785a6c
Step 3/3 : ENTRYPOINT [ "dotnet", "/app/licenseGen.dll", "--core", "/app/Core.dll", "--cert", "/cert.pfx" ]
 ---> Using cache
 ---> f00f07f76b7a
Successfully built f00f07f76b7a
Successfully tagged bitbetter/licensegen:latest

@tam481
Copy link
Author

tam481 commented May 26, 2019

Below are the contents of the csproj:

root@debian:/opt/BitBetter/src/licenseGen# cat licenseGen.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.0" />
    <PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
  </ItemGroup>

</Project>

@JeffAlyanak
Copy link
Collaborator

Below are the contents of the csproj:

root@debian:/opt/BitBetter/src/licenseGen# cat licenseGen.csproj

Have you been following all of the steps as the root user? I wouldn't recommend that for security and environment reasons.

We've seen users in the past having issues getting the dotnet builds and the docker containers working correctly due to the way that dotnet and docker set environment variables.

In the past, those issues have been solved by using a regular, unprivileged user instead.

@tam481
Copy link
Author

tam481 commented May 26, 2019

oh OK. I thought I wouldn't be able to execute the commands as a standard user. Wouldn't doing sudo ./build.sh be the same as running it as root?

@tam481
Copy link
Author

tam481 commented May 26, 2019

I can't run ./build.sh or the dotnet add package Newtonsoft.Json --version 11.0.0 without sudo

I'm I doing this all wrong?

@JeffAlyanak
Copy link
Collaborator

JeffAlyanak commented May 26, 2019

You shouldn't have to run with sudo at all for anything other than installing the prerequisites.

If you followed the recommended steps when installing docker, you would have added an unprivileged user to the docker usergroup with a command like sudo usermod -aG docker someuser and you'd have used sudo to install any required packages (dotnet sdk) but aside from that nothing needs sudo or root access.

As a rule of thumb, you should never run anything with root that doesn't require root.

The reason you can't run the dotnet command is probably because the BitBetter directory and the files inside are owned by root now. You should chown those to the correct user or git clone them as an unprivileged user and then go through those instructions again without using the root user.

@tam481
Copy link
Author

tam481 commented May 26, 2019

OK. Just recreated everything and I'm doing things as my non-privileged user "user"

Everything is installed in /opt/
user owns bwdata and BitBetter and the bitwarden.sh scripts
It is also a member of the docker group and I've managed to get Bitwarden started

I'm still getting the same error message though!

user@debian:/opt/BitBetter/src/licenseGen$ ./run.sh /opt/BitBetter/.keys/cert.pfx user User user@email.com GUID
Oops: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.

File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.GetSerializableMembers(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperties(Type type, MemberSerialization memberSerialization)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at bitwardenSelfLicensor.Program.GenerateUserLicense(X509Certificate2 cert, String corePath, String userName, String email, Guid userId, String key) in /opt/BitBetter/src/licenseGen/Program.cs:line 175
   at bitwardenSelfLicensor.Program.<>c__DisplayClass0_1.<Main>b__6() in /opt/BitBetter/src/licenseGen/Program.cs:line 75
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at bitwardenSelfLicensor.Program.Main(String[] args) in /opt/BitBetter/src/licenseGen/Program.cs:line 137

I've changed details such as user, email and GUID before posting but the actual command has the correct ones.

What else can I do now?

@JeffAlyanak
Copy link
Collaborator

JeffAlyanak commented May 26, 2019

For now I've been unable to recreate this issue, trying clean installs on fresh Debian 9 and Ubuntu 19.04 systems.

What operating system and OS version are you attempting this install on?

Using the most recent version of BitBetter (commit 15371c3), the default version that installs with the dotnet-sdk-2.1 (oddly enough, this is 2.2.300) and the most recent version of Bitwarden I can't replicate the issue. I've also tried using the version of the dotnet-sdk that you have (2.1.700), but still can't replicate the issue.

Perhaps you can try manually installing a different version of the dotnet-sdk. I believe that Microsoft simply provides package names for different versions, so you can try installing dotnet-sdk-2.2.

Remember that you have to rebuild the license generator again after installing a new version of dotnet-sdk and updating the dotnet packages with dotnet add package Newtonsoft.Json --version 11.0.0.

@tam481
Copy link
Author

tam481 commented May 26, 2019

Thanks @JeffAlyanak
I am running a clean version of Debian 9

user@debian:~$ cat /etc/*-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
user@debian:~$ cat /proc/version
Linux version 4.9.0-9-amd64 (debian-kernel@lists.debian.org) (gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1) ) #1 SMP Debian 4.9.168-1+deb9u2 (2019-05-13)

Followed the instructions on the main page for BitBetter and managed to build the Docker images for both BitBetter and Bitwarden with no issues other than the warning about the version being 11.0.1 instead of 11.0.0 and that's all.

Also, with regards to the certificate, this is the self-signed one described under "Note: Manually generating Certificate & Key" right?

I even searched all the files inside licenceGen for 12.0.0 and could not find any reference. All references I found are for version 11.0.0 as expected.

I'm doing this on a virtual machine and I've reverted to the snapshot that only has the minimum Debian installation plus unzip and sudo and nothing else.

I will try a different version of dotnet and see.

@tam481
Copy link
Author

tam481 commented May 26, 2019

I've not had much luck with the commit you referred to above (git clone https://github.com/jakeswenson/BitBetter.git). This is the one right?

Not much luck with dotnet2.2 either :-(

Edit: removed references to new issue #20 which is now closed.

@JeffAlyanak
Copy link
Collaborator

Since your issue with bitbetter/identity has been resolved by rebuilding can you try deleting and rebuilding the license gen and posting the resulting output below if that does not solve the issue?

@tam481
Copy link
Author

tam481 commented May 28, 2019

Tried again multiple times last night and in a completely new environment (lab at work) with a proper certificate and everything. Still getting the same error message!

I cannot for the life of me figure out where the reference to 12.0.0.0 is!

Oops: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified.

File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.GetSerializableMembers(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateProperties(Type type, MemberSerialization memberSerialization)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at bitwardenSelfLicensor.Program.GenerateOrgLicense(X509Certificate2 cert, String corePath, String userName, String email, Guid instalId, String key) in /opt/BitBetter/src/licenseGen/Program.cs:line 220
   at bitwardenSelfLicensor.Program.<>c__DisplayClass0_2.<Main>b__7() in /opt/BitBetter/src/licenseGen/Program.cs:line 121
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at bitwardenSelfLicensor.Program.Main(String[] args) in /opt/BitBetter/src/licenseGen/Program.cs:line 137

@tam481
Copy link
Author

tam481 commented May 28, 2019

Hello mate. I cracked it. I ran dotnet add package Newtonsoft.Json --version 12.0.2 then dotnet add package Newtonsoft.Json --version 12.0.1

Then attempted to generate a licence and it generated one.

@JeffAlyanak
Copy link
Collaborator

I've played around a bit with this tonight and I can't replicate the same issues that you had. For now I'm just going to file this under Unsolved Mysteries and close it as I'm hoping to automate the dotnet setup anyway.

@DB-CL
Copy link

DB-CL commented Jun 3, 2019

I had the exact same issue on a fresh debian 9 install. I cannot provide more informations than @tam481 but his solution is working.

@JeffAlyanak
Copy link
Collaborator

Hey @DB-CL, this issue has been fixed in the upcoming Interactive Mode release ( #23 ). It's still awaiting review and approval from another contributor before it hits the master branch, but it does appear to address this issue with newer versions of the dotnet-sdk.

@JeffAlyanak
Copy link
Collaborator

The version of Newtonsoft in the newest commit has been bumped and should work with a wider variety of systems and versions of dotnet-sdk now.

The changes have merged to the master branch with PR #23.

Theoretically, you shouldn't even need to run the dotnet add package commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants