Docker Swarm Mode Ports 2377, 7946, 4789

The docker docs say that for swarm mode to work:

Open protocols and ports between the hosts

The following ports must be available. On some systems, these ports are open by default.

  • TCP port 2377 for cluster management communications
  • TCP and UDP port 7946 for communication among nodes
  • UDP port 4789 for overlay network traffic

If you plan on creating an overlay network with encryption (--opt encrypted), you also need to ensure ip protocol 50 (ESP) traffic is allowed

Here is how one can test if these ports are indeed open. Use the nc command like follows:

On swarm manager:

siddjain@goldenrwr-ca0:~$ nc -zv localhost 2377

Connection to localhost 2377 port [tcp/*] succeeded!

siddjain@goldenrwr-ca0:~$ nc -zv localhost 7946

Connection to localhost 7946 port [tcp/*] succeeded!

siddjain@goldenrwr-ca0:~$ nc -uzv localhost 4789

Connection to localhost 4789 port [udp/*] succeeded!

siddjain@goldenrwr-ca0:~$ nc -uzv localhost 7946

Connection to localhost 7946 port [udp/*] succeeded!

On swarm worker note that port 2377 is refused:

siddjain@goldenrwr-peer0:~$ nc -zv localhost 2377

nc: connect to localhost port 2377 (tcp) failed: Connection refused

siddjain@goldenrwr-peer0:~$ nc -zv localhost 7946

Connection to localhost 7946 port [tcp/*] succeeded!

siddjain@goldenrwr-peer0:~$ nc -uzv localhost 4789

Connection to localhost 4789 port [udp/*] succeeded!

siddjain@goldenrwr-peer0:~$ nc -uzv localhost 7946

Connection to localhost 7946 port [udp/*] succeeded!

Posted in Software | Leave a comment

Running Custom Build of Hyperledger Fabric Orderer

If you want to run it inside a docker container:

If you want to run a custom build of the orderer, make sure you set the FABRIC_CFG_PATH and have an orderer.yaml inside FABRIC_CFG_PATH. The docker container will have it setup automatically for you. Copy the orderer.yaml from container to local machine using docker cp.

Install fabric from github under your $GOPATH/src/github.com/hyperledger

To build orderer simply run go build from the orderer folder. The orderer will require a few variables to be set before you can run it like CHANNEL_TX_FILE=./channel.tx GENESIS_BLOCK_FILE=./genesis.block ORDERER_GENERAL_GENESISFILE=./genesis.block ORDERER_GENERAL_LOCALMSPID=ordMSP ORDERER_GENERAL_LOCALMSPDIR=./msp.

One handy command is docker inspect <image-name>. If we run it on fabric-ca-orderer, among other things it shows

 “Env”: [

                “PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin”,

                “FABRIC_CFG_PATH=/etc/hyperledger/fabric”

            ],

            “Cmd”: [

                “orderer”

            ],

Cmd contains the command the container will execute on starting. There is another field called Entrypoint which does the same thing. When both an ENTRYPOINT and CMD are specified, the CMD string(s) will be appended to the ENTRYPOINT in order to generate the container’s command string. More details at https://www.ctl.io/developers/blog/post/dockerfile-entrypoint-vs-cmd/

Posted in Software | Leave a comment

VS Code Setup

Getting Bash IDE to work in VS Code:

Installing bash-language-server in non global mode:

https://github.com/mads-hartmann/bash-language-server/issues/97

Open VS Code settings by clicking on gear icon at bottom left of VS Code

To Install/Update Go Tools View -> Command Palette (Cmd+Shift+P)

View -> Command Palette (Cmd+Shift+P)

To open a file quickly, Cmd+P

By default Cmd+P will open file in the current TAB and whatever file is currently open will be closed as a result. This is extremely annoying. Disable the Enable Preview checkbox to tell VS Code to open file in a new TAB.

Remove annoying tslint errors/warnings in vs code

Launching VS Code from command line

To enable launching VS Code from the command line, run following in Command Palette (Cmd+Shift+P on Mac)

Shell Command: Install 'Code' command in path

You should then be able run following on the terminal:

$ code --help

Setting VS Code as the mergetool and difftool for Git

You can use VS Code as the mergetool and difftool of choice for Git by editing ~/.gitconfig file and adding following lines to it (source):

[core]
  editor = code --wait
[diff]
  tool = vscode
[difftool "vscode"]
  cmd = code --wait --diff $LOCAL $REMOTE
[merge]
  tool = vscode
[mergetool "vscode"]
  cmd = code --wait $MERGED

Using VS Code as the mergetool

Once you have setup VS Code as the mergetool, you will see below as example wherever there are merge conflicts

If you like to see the changes side-by-side click on Compare Changes. That should give you a result like below:

If you made a selection (accept current change, accept incoming change, accept both changes) and want to go back simply use Edit -> Undo (Cmd+Z)

Further reading: https://stackoverflow.com/questions/38216541/visual-studio-code-how-to-resolve-merge-conflicts-with-git

Open settings.json

Open the command pallete (Cmd+Shift+P on Mac) and from there:

or just open it like this:

$ vi $HOME/Library/Application\ Support/Code/User/settings.json

e.g., you can set

"[markdown]": {
    "editor.formatOnSave": false,
  }

to disable format on save for markdown files. ref

How to see what extensions you have installed?

$ ls ~/.vscode/extensions                                      ⬡ 20.3.1 [±master ✓▴]
donjayamanne.githistory-0.6.20
esbenp.prettier-vscode-10.1.0
extensions.json
ms-dotnettools.csharp-2.0.328-darwin-arm64
ms-dotnettools.vscode-dotnet-runtime-1.6.0
ms-python.python-2023.14.0
ms-python.vscode-pylance-2023.8.20
ms-vscode.cmake-tools-1.15.31
ms-vscode.cpptools-1.16.3-darwin-arm64
ms-vscode.cpptools-extension-pack-1.3.0
ms-vscode.cpptools-themes-2.0.0
patbenatar.advanced-new-file-1.2.2
redhat.java-1.21.0-darwin-arm64
svelte.svelte-vscode-107.9.0
twxs.cmake-0.0.17
visualstudioexptteam.intellicode-api-usage-examples-0.2.7
visualstudioexptteam.vscodeintellicode-1.2.30
vscjava.vscode-java-debug-0.53.0
vscjava.vscode-java-dependency-0.23.1
vscjava.vscode-java-pack-0.25.13
vscjava.vscode-java-test-0.39.1
vscjava.vscode-maven-0.42.0
ExtensionPurpose
donjayamanne.githistory-0.6.20this extension is good for diffing commits. VS Code has a built-in Timeline viewer but it can only be used to diff a file not a commit.

What are all the folders where VS Code stores files on Mac?

From this answer:

rm -fr ~/Library/Preferences/com.microsoft.VSCode.helper.plist 
rm -fr ~/Library/Preferences/com.microsoft.VSCode.plist 
rm -fr ~/Library/Caches/com.microsoft.VSCode
rm -fr ~/Library/Caches/com.microsoft.VSCode.ShipIt/
rm -fr ~/Library/Application\ Support/Code/
rm -fr ~/Library/Saved\ Application\ State/com.microsoft.VSCode.savedState/
rm -fr ~/.vscode/

also see this.

Troubleshooting Keyboard Shortcuts

TL;DR: If keyboard shortcuts don’t work as expected check if Karabiner Elements is causing the problem. N/A if you are not using Karabiner Elements.

I ran into a problem when F12 was no longer taking me to definition. It was instead increasing the volume. Turns out the problem had to do with Karabiner Elements. In my Karabiner Elements I had following configuration:

The fix is simply to check the box that says Use all F1, F2, etc. keys as standard function keys.

Another day I found F11 was not working as expected in VS Code. Its supposed to step inside a function while debugging. The culprit was the setting in System Preferences -> Keyboard -> Shortcuts -> Mission Control which was causing F11 to show the desktop.

After unchecking the box F11 started working in VS Code.

10 Tips on Java Programming with VS Code

  1. Install following extensions:
    1. Extension Pack for Java by Microsoft. It contains 6 extensions:
      1. Language Support for Java
      2. Debugger for Java
      3. Test Runner for Java
      4. Maven for Java
      5. Project Manager for Java
      6. IntelliCode
  2. In launch.json here is how you specify environment variables (env), program arguments (args) and arguments to JVM (vmArgs) and additional dependencies to the classpath besides those in pom.xml:
{
            "type": "java",
            "name": "Launch App",
            "request": "launch",
            "mainClass": "com.example.App",
            "projectName": "rsync",
            "vmArgs": "-enableassertions -javaagent:/Users/xxx/.m2/repository/com/example/instrumentation/1.0-SNAPSHOT/instrumentation-1.0-SNAPSHOT.jar",
            "args": "rsync.properties",
            "env": {
                "GOOGLE_APPLICATION_CREDENTIALS": "$HOME/keyfiles/gcp.json"
            },
"classPaths": [
                "$Auto",                "/Users/me/.m2/repository/com/oracle/database/jdbc/ojdbc10/19.15.0.0.1/ojdbc10-19.15.0.0.1.jar"
            ]
        }
  1. Error: Build path specifies execution environment JavaSE-10. There are no JREs installed in the workspace that are strictly compatible.
    edit pom.xml and add <java.version> in that. After that do not forget to clean Java language server workspace (Cmd+Shift+P -> Java: clean) and restart vs code.
  2. Shift+Alt+O will add required imports and also remove unused imports. Alt is also known as Option key.
  3. Shift+Alt+F will format the file. You can open Settings and turn on Format on Save. this way VS Code will auto-format the code when its saved.
  4. Frequently when you try to debug (F5) you will get an error complaining the build failed even though there is nothing wrong with the code and you can execute it from the command line. VS Code also asks do you want to proceed even if the build failed. Error occurred while building workspace. The solution is to clean the workspace directory. See this.
  5. enable java assertions. see this
  6. To create a new project use Cmd+Shift+P: Maven: Create Maven project.


As of this writing the generated pom.xml does not contain <java.version>. Add it as best practice as shown below. I have also changed JDK version to 11.

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
<java.version>11</java.version>

  1. You can add new Maven commands by editing ~/Library/Application Support/Code/User/settings.json. E.g.:
"maven.terminal.favorites": [
        {
            "alias": "full-build without tests",
            "command": "clean package -DskipTests"
        }                       
    ]

then you can use this command as follows

The Maven extension executes Maven by opening a terminal session and then calling Maven in that session. Maven requires the JAVA_HOME environment variable to be set. Maven will also look for other variables such as MAVEN_OPTS. If you prefer not to set those variables permanently you can configure them, or any other environment variable, in settings:

{
    "maven.terminal.customEnv": [
        {
            "environmentVariable": "MAVEN_OPTS",               // variable name
            "value": "-Xms1024m -Xmx4096m"                     // value
        },
        {
            "environmentVariable": "JAVA_HOME",                // variable name
            "value": "C:\\Program Files\\Java\\jdk-9.0.4"      // value
        }
    ]
}

this will add dependency to pom.xml

  • Another useful shortcut is Source Action... to automatically generate constructors and getters / setters. Watch the videos here.
  • You can add additional dependencies to your classpath in addition to those in pom.xml by editing launch.json like so:
"classPaths": [
                "$Auto",                "/Users/me/.m2/repository/com/oracle/database/jdbc/ojdbc10/19.15.0.0.1/ojdbc10-19.15.0.0.1.jar"
            ]

$Auto adds all dependencies defined in pom.xml. Refer this. Warning: Using environment variables (e.g., using $HOME instead of /Users/me) in the classpath did not work for me. See this.

  • Note that VS Code does not use the javac compiler to compile your code. Instead it uses a compiler that ships with Eclipse JDT (java development tools). more on it here.

VSCode Python Tips (Problems and Solutions)

Not able to step into the code of a library or stick breakpoints in library code

Make sure that justMyCode is set to false in launch.json. Example:

{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal",
    "justMyCode": false
}

How to use a pre-existing virtual environment?

This is done using the steps described hereSelect and activate an environment.

If you would prefer to select a specific environment, use the Python: Select Interpreter command from the Command Palette (⇧⌘P).

How to clean up VS Code junk?

After 1 year of intense coding, VS Code accumulated 4GB of data. don’t know what is essential and what is junk:

>>> du -sh ~/Library/Application\ Support/Code/                                                                                                                                                                                                 15:25.12 Wed May 15 2024 >>>
4.3G	/Users/xxx/Library/Application Support/Code/

3GB is in

>>> du -sh ~/Library/Application\ Support/Code/User/workspaceStorage                                                                                                                                                                            15:25.41 Wed May 15 2024 >>>
2.9G	/Users/xxx/Library/Application Support/Code/User/workspaceStorage

it seems that this folder can be deleted [1]. Also you can delete ~/Library/Application\ Support/Code/CachedData and ~/Library/Application\ Support/Code/Cache folders. After deleting these folders the size went down to less than a GB.

>> rm -rf /Users/xxx/Library/Application\ Support/Code/User/workspaceStorage
>> rm -rf /Users/xxx/Library/Application\ Support/Code/Cache
>> rm -rf /Users/xxx/Library/Application\ Support/Code/CachedData
>>> du -sh /Users/xxx/Library/Application\ Support/Code                                                                                                                                                                                    16:10.18 Wed May 15 2024 >>>
862M	/Users/xxx/Library/Application Support/Code

Posted in Computers, Software | Tagged , | Leave a comment

Ethereum vs. Hyperledger: The Epilogue

I was very excited to work with Hyperledger when I first did a comparison between Ethereum vs. Hyperledger [1]. The ability to write chaincode in javascript was especially appealing to me. However after more than a month of spending time in the trenches and doing Hyperledger Fabric development, my opinions changed. If I were to revisit Part I of Ethereum vs. Hyperledger [1], I would add one more row to the table as follows:

 EthereumHyperledger
Developer ExperienceF

I haven’t done any programming with Ethereum so don’t know how developer friendly it is but can safely say that Hyperledger scores an F on the developer experience. Lets try to break down the developer experience on following competencies:

  1. Works without any issues
  2. SDK provides good, exhaustive and bug-free code samples showing how to write code and exercise functionality
  3. Comprehensive and accurate documentation
  4. Tech Support: When there is an issue, there is a helpful community to provide support

Rating Scale.

A – excellent. Scores +1 on all dimensions above
B – Good. Better than other alternatives out there
C – Fair. comparable to other alternative platforms
D – Poor. there exist better alternatives out there
F – Fail. -1 on all of the above dimensions

Hyperledger proudly scores an F

  • Broken out of the box: e.g., https://stackoverflow.com/questions/53506205/install-samples-binaries-and-docker-images-not-working-on-mac. Its like you ordered something from amazon and its broken out of the box. Looks like HL team spend no time testing the code works on a mac
  • Buggy Samples: e.g., https://stackoverflow.com/questions/51436123/unable-to-find-neweventhub-function. Another example: https://jira.hyperledger.org/browse/FAB-13070
  • Samples of limited use and help: e.g.,
    • everywhere in the samples they keep on using cryptogen and then write that cryptogen should not be used in production.
    • In all the samples, the private crypto keys are blatantly exposed [example] and there is no sample showing how to protect them in a prod environment.
    • All the samples create a network in which all the nodes are running on the same computer. There is no sample showing how to create a real-world network spanning multiple computers
    • the list goes on. Basically there is no sample showing how to write a production quality app
  • Incorrect documentation: Worse than missing documentation is incorrect documentation and Fabric is full of it. e.g., instructions on https://github.com/hyperledger/fabric-samples/tree/release-1.3/balance-transfer/typescript say that Node.js v6.9.0 – 6.10.0 ( Node v7+ is not supported ) is required whereas the instructions elsewhere say that Node.js v8.4.0 or higher. Even the HL Fabric prerequisites say that If you will be developing applications for Hyperledger Fabric leveraging the Hyperledger Fabric SDK for Node.js, you will need to have version 8.9.x of Node.js installed. I kept a screenshot of the incorrect documentation here in case it gets fixed later. This e.g., caused me lot of trouble and wasted time. As I found out thae hard way, in reality Node.js v6.9.0-6.10.0 will land you in trouble. This is because Promises were introduced only in version 8 of Node.

    Another example of incorrect documentation is here on this line

    let key = enrollment.key.toBytes();

    I preserved a screenshot here. In reality the key needs to be a string and if you use a byte array, there will be an error.
  • Missing Documentation: Hyperledger Fabric relies on a dozen configuration files. Some of them are listed below:
    • configtx.yaml
    • orderer.yaml
    • fabric-ca-server-config.yaml
    • fabric-ca-client-config.yaml
    • core.yaml
    • peer.yaml

nowhere can one find explanation of all the fields in these yaml files. More examples showing the sad state of documentation, various bugs and incomplete features [1, 2, 3, 4, 5, 6]

Some things that are unrelated to developer experience but worth mentioning (identifying open gaps):

  • No support for kubernetes [ref]. Running HL Fabric on Kubernetes requires that you provide privileged access in order to run the chaincode. There are also some other issues as well. As a result, running HLF on kubernetes and thus OpenShift, is not recommended for production.
  • I am also not sure if Hyperledger Fabric really comes with a true consensus protocol [1]
  • And it seems to come with a some security loopholes [ref]. Essentially in order to run fabric, you have to allow peer nodes access to the the docker daemon which they need in order to spin up a new container to run the chaincode; but giving this access is risky as illustrated in [ref]. That is why there is no support for kubernetes.

A list of questions I have asked on fabric DL. And on SO. Bugs I have filed against Fabric.

Conclusion: If you haven’t already made lot of investment in Hyperledger Fabric, it is best to stay away from it.

Posted in Software | Leave a comment

Ethereum vs. Hyperledger – Which is better? Part I

Ethereum
Hyperledger
Built for enterprise
red_cross

checkmark-xxl

Scalability
red_cross

 

checkmark-xxl

Ability to write chaincode in familiar languages
red_cross

 

checkmark-xxl

Transactions can be non-deterministic
red_cross

 

checkmark-xxl

Support for private data
red_cross

checkmark-xxl

Enterprise Footprint
red_cross

checkmark-xxl

Cryptocurrency not needed
red_cross

checkmark-xxl

Membership Service Provider
red_cross

checkmark-xxl

  • Built For Enterprise:

https://www.verypossible.com/blog/the-pros-and-cons-of-hyperledger-fabric
“most enterprise apps would get tilted towards Fabric, whereas Ethereum would continue to be a hotbed for dApps that are more B2C”

https://www.quora.com/What-are-the-pros-and-cons-of-developing-on-Hyperledger-vs-Ethereum
Ethereum has the EVM running the Smart Contracts for applications that are attributed to being decentralized and are for mass consumption.
On the other hand, Hyperledger leverages blockchain technology for business.

  • Scalability:
  1. Ethereum uses a PoW consensus which is expensive whereas HL uses Apache Kafka to order the transactions and a customizable endorsement policy to drive consensus. Fabric claims its consensus protocol can be changed and customized.
  2. Ethereum uses order-execute architecture which requires all peers to execute every transaction whereas HL uses execute-order-validate architecture
  3. Ethereum can process 25 transactions per sec [1] whereas HL Fabric can process 3500 TPS [2]
  4. The experimental results, based on varying number of transactions, show that Hyperledger Fabric consistently outperforms Ethereum across all evaluation metrics which are execution time, latency and throughput. [3]. Also see [4] for more independent tests confirming the same
  • Ability to write chaincode in familiar languages: Ethereum smart contracts have to be written in Solidity language. HL Fabric chaincode can be written in Go, NodeJS or Java
  • Transactions can be non-deterministic: this is the reason why Ethereum does not support writing smart contract in a general purpose programming language
  • Support for private data: HL provides support for private data using channels and side-db. In Ethereum there are no means to issue a private transaction between members [3].
  • Enterprise Footprint: This is the most important factor that should be used to guide which platform to choose. Many big and reputed enterprises have deployed HL Fabric based blockchain solutions e.g.: walmarttradelenshu-manity.co, AID:Tech, MedicalChain. I am not aware of any enterprise blockchain based on Ethereum (although I have not done exhaustive research here; also see this). JPMorgan has taken a fork of Ethereum and developed a new offering known as Quorum. there are enterprise apps built on Quorum. But Quorum is not Ethereum.
  • Cryptocurrency not needed: Ethereum requires use of a cryptocurrency known as Ether. HL Fabric has no concept of a cryptocurrency as it is N/A for enterprise apps.
  • Membership Service Provider: A MSP is what enables creation of a permissioned blockchain. Ethereum does not some with any MSP.

It is possible that Ethereum team will work to address the issues above so that its used in enterprise (see this). But in the meantime there is no reason not to use a platform that was specifically built for business.

Posted in Software | Tagged | Leave a comment

Understanding user registration and enrollment in Hyperledger Fabric

TL;DR

  • The bootstrap identity is defined by the username:password used in -b argument to fabric-ca-server start
  • The bootstrap identity is special and does not need a registration step. This is because it is automatically registered when the server starts
  • All other identities will first need to be registered by fabric-ca-client before they can be enrolled. The identity performing the register request must be currently enrolled, and must also have the proper authority to register the type of the identity that is being registered. More details at https://hyperledger-fabric-ca.readthedocs.io/en/release-1.4/users-guide.html#registering-a-new-identity
  • If an identity that is not registered is tried to enroll, the enrollment will fail with following message on the fabric-ca server: “Failed to get user: : scode: 404, code: 63, msg: Failed to get User: sql: no rows in result set”. This gives us a clue as to what registration really does
  • fabric-ca-client assumes the identity of whatever is in $FABRIC_CA_HOME/msp by default. This can be changed by using the -M flag in command line args to fabric-ca-client. If there is no identity stored in the mspdir directory you will get below error no matter what command you try to execute with fabric-ca-client (except the enroll command in which case the directory should be empty). more info at https://stackoverflow.com/a/55249822/147530:
    [ERROR] Enrollment check failed: Idemix enrollment information does not exist
  • by default FABRIC_CA_HOME is set to /etc/hyperledger/fabric-ca-server
  • If TLS is enabled then:
    • we need to connect using https not http
    • we need to pass –tls.certfiles X to fabric-ca-client where X = the cert of the CA who issued cert to the server

When I read hyperledger docs and specifically the section on Enrolling Bootstrap Identity, I noticed it does not register a user before enrolling. This led me to think that a user can be enrolled without registering but that is not true. If one tries to enroll a user who has not been registered, the request will fail with following error message in fabric-ca server logs:


"Failed to get user: : scode: 404, code: 63, msg: Failed to get User: sql: no rows in result set"

So how come the bootstrap identity can be enrolled without registering? The answer is that when enrolling the bootstrap identity, the username and password must match the username and password given when fabric-ca-server was started. When the server is started, it automatically registers an identity with given username and password i.e., it stores a row in sql database with given username and password – that is what registration is about. When fabric-ca-client tries to enroll a user the server will check the sql database to first verify that the user exists and fail with above message otherwise. So all users except the bootstrap identity need to be registered first before enrolling.

we illustrate this below with some actual commands. Create a docker-compose.yaml file with following contents:

Screen Shot 2018-12-28 at 10.11.00 AM

now run it


$ docker-compose up

It should spin up a docker container named my-container. Log into the container:


$ docker exec -it my-container /bin/bash

since we have enabled TLS we need to connect using https instead of http. Also we need to add localhost to FABRIC_CA_SERVER_CSR_HOSTS otherwise will get an error saying

x509: certificate is valid for rca-ord, not localhost

run

root@1e046d83410d:/# fabric-ca-client enroll -u https://user:userpw@localhost:7054
2018/12/28 18:07:26 [INFO] TLS Enabled
Error: Failed to get client TLS config: No trusted root certificates for TLS were provided

what happened? we enabled TLS. so when the client tried to connect to the server, the server give it a cert but the client cannot verify authenticity of the certificate. The client needs to have the CA that issued cert to server in its trusted CA list. So to fix it run:

root@1e046d83410d:/# fabric-ca-client enroll -u https://user:userpw@localhost:7054 --tls.certfiles $FABRIC_CA_SERVER_HOME/tls-cert.pem
2018/12/28 17:32:28 [INFO] TLS Enabled
2018/12/28 17:32:28 [INFO] generating key: &{A:ecdsa S:256}
2018/12/28 17:32:28 [INFO] encoded CSR
Error: Response from server: Error Code: 20 - Authentication failure
on server:
my-container | 2018/12/28 17:32:28 [INFO] 127.0.0.1:58882 POST /enroll 401 23 "Failed to get user: : scode: 404, code: 63, msg: Failed to get User: sql: no rows in result set"

this is because user is not registered.

root@1e046d83410d:/# fabric-ca-client enroll -u https://admin:adminpw@localhost:7054 --tls.certfiles $FABRIC_CA_SERVER_HOME/tls-cert.pem
2018/12/28 17:25:38 [INFO] TLS Enabled
2018/12/28 17:25:38 [INFO] generating key: &{A:ecdsa S:256}
2018/12/28 17:25:38 [INFO] encoded CSR
2018/12/28 17:25:38 [INFO] Stored client certificate at /etc/hyperledger/fabric-ca-server/msp/signcerts/cert.pem
2018/12/28 17:25:38 [INFO] Stored root CA certificate at /etc/hyperledger/fabric-ca-server/msp/cacerts/localhost-7054.pem
2018/12/28 17:25:38 [INFO] Stored Issuer public key at /etc/hyperledger/fabric-ca-server/msp/IssuerPublicKey
2018/12/28 17:25:38 [INFO] Stored Issuer revocation public key at /etc/hyperledger/fabric-ca-server/msp/IssuerRevocationPublicKey

note we gave same username and password as the one used when starting the server. This is what defines the bootstrap identity – it is the user who started the server. And the command succeeds now. we can look at the cert of bootstrap identity as follows:

root@1e046d83410d:/# openssl x509 -in /etc/hyperledger/fabric-ca-server/msp/signcerts/cert.pem -text -noout
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
29:dd:ac:fb:0a:83:19:4d:26:58:c0:56:37:79:6b:a6:42:a4:d1:b9
Signature Algorithm: ecdsa-with-SHA256
Issuer: C=US, ST=North Carolina, O=Hyperledger, OU=Fabric, CN=rca-ord
Validity
Not Before: Dec 28 17:21:00 2018 GMT
Not After : Dec 28 17:26:00 2019 GMT
Subject: C=US, ST=North Carolina, O=Hyperledger, OU=client, CN=admin
Subject Public Key Info:
Public Key Algorithm: id-ecPublicKey
Public-Key: (256 bit)
pub:
04:9a:77:1f:60:f1:0b:85:31:24:31:5f:c1:b2:5b:
6f:e4:32:1f:03:41:a5:d2:ce:f3:e5:bc:ba:12:d8:
98:65:04:52:72:d4:16:ed:32:f8:d5:d5:c5:e7:c2:
0f:c6:b8:a9:2f:89:5c:81:a2:36:28:f5:5b:35:1e:
75:61:dd:ea:ae
ASN1 OID: prime256v1
NIST CURVE: P-256
X509v3 extensions:
X509v3 Key Usage: critical
Digital Signature
X509v3 Basic Constraints: critical
CA:FALSE
X509v3 Subject Key Identifier:
A9:7F:79:5E:83:8D:6E:F8:57:6D:B2:C5:FE:84:13:1C:A3:AD:5A:22
X509v3 Authority Key Identifier:
keyid:7F:16:BC:D0:A7:7E:4C:75:7C:73:52:8D:A5:17:45:5C:9E:B9:D7:10
X509v3 Subject Alternative Name:
DNS:1e046d83410d
Signature Algorithm: ecdsa-with-SHA256
30:45:02:21:00:cc:08:ff:bd:73:a4:c6:ec:7a:51:3d:43:f8:
a8:72:74:46:4b:f4:33:e7:58:76:00:79:94:a4:f7:69:d9:16:
7d:02:20:5a:9e:af:99:3c:60:dd:e8:46:12:e9:56:3d:90:0b:
d4:d5:28:94:b9:71:da:e7:4d:4f:71:2a:6a:2e:66:e2:45

Lets try to enroll the user defined in BOOTSTRAP_USER_PASS variable when we started the server

root@1e046d83410d:/# fabric-ca-client enroll -u https://rca-ord-admin:rca-ord-adminpw@localhost:7054 --tls.certfiles $FABRIC_CA_SERVER_HOME/tls-cert.pem
2018/12/28 17:36:03 [INFO] TLS Enabled
2018/12/28 17:36:03 [INFO] generating key: &{A:ecdsa S:256}
2018/12/28 17:36:03 [INFO] encoded CSR
Error: Response from server: Error Code: 20 - Authentication failure
my-container | 2018/12/28 17:36:03 [INFO] 127.0.0.1:58884 POST /enroll 401 23 "Failed to get user: : scode: 404, code: 63, msg: Failed to get User: sql: no rows in result set"

it does not work. Lets try to enroll a new user

root@1e046d83410d:/# fabric-ca-client register --id.name admin2 --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,admin=true:ecert' -u https://localhost:7054 --tls.certfiles $FABRIC_CA_SERVER_HOME/tls-cert.pem
2018/12/28 17:42:34 [INFO] Configuration file location: /etc/hyperledger/fabric-ca-server/fabric-ca-client-config.yaml
2018/12/28 17:42:34 [INFO] TLS Enabled
2018/12/28 17:42:34 [INFO] TLS Enabled
Password: mMNrwlSgLXqE

Things to note:

  1. Note that we enrolled bootstrap user earlier and above command ran under its identity. the fabric-ca-client will take identity from $FABRIC_CA_HOME/msp
  2. Since we did not specify any password the server generated one for us

Example showing password set at time of registration:

root@1e046d83410d:/# fabric-ca-client register --id.name test-user1 --id.secret test-user1pw --id.affiliation org1.department1 -u https://localhost:7054 --tls.certfiles $FABRIC_CA_SERVER_HOME/tls-cert.pem
2018/12/28 17:46:03 [INFO] Configuration file location: /etc/hyperledger/fabric-ca-server/fabric-ca-client-config.yaml
2018/12/28 17:46:03 [INFO] TLS Enabled
2018/12/28 17:46:03 [INFO] TLS Enabled
Password: test-user1pw

Also note what happens below:

root@1e046d83410d:/# mv /etc/hyperledger/fabric-ca-server/msp /etc/hyperledger/fabric-ca-server/msp1
root@1e046d83410d:/# fabric-ca-client register --id.name test-user2 --id.secret test-user2pw --id.affiliation org1.department1 -u https://localhost:7054 --tls.certfiles $FABRIC_CA_SERVER_HOME/tls-cert.pem
2018/12/28 19:38:00 [INFO] Configuration file location: /etc/hyperledger/fabric-ca-server/fabric-ca-client-config.yaml
2018/12/28 19:38:00 [INFO] TLS Enabled
2018/12/28 19:38:00 [ERROR] Enrollment check failed: Idemix enrollment information does not exist
Error: Enrollment information does not exist. Please execute enroll command first. Example: fabric-ca-client enroll -u http://user:userpw@serverAddr:serverPort

So it looks like fabric-ca-client is taking its identity from /etc/hyperledger/fabric-ca-server/msp which is same as $FABRIC_CA_HOME/msp

PS: More details can be found in my book on Programming Hyperledger Fabric.

Posted in Software | Tagged , | 1 Comment

E1219 23:48:19.159391389 19 ssl_transport_security.cc:238] Could not get common name of subject from certificate.

Returned back from vacation to find this error when I try to run hyperledger fabric sample. It used to work just fine before I left on vacation. What gives?

WITSC02X6385JGH:fabric-ca sjain68$ docker logs -f dev-peer1-jnj-mycc-1.0

> chaincode@1.0.0 start /usr/local/src

> node chaincode.js "--peer.address" "peer1-jnj:7052"


E1219 23:48:19.159391389      19 ssl_transport_security.cc:238] Could not get common name of subject from certificate.

{ fcn: 'create', params: [ '00000' ] }

SyntaxError: Unexpected token  in JSON at position 0

    at JSON.parse ()

    at new ClientIdentity (/usr/local/src/node_modules/fabric-shim/lib/chaincode.js:246:27)

    at Chaincode.Invoke (/usr/local/src/chaincode.js:29:17)

Turns out there is some problem with v0.3.4 of X509 library that was released recently. Change dependencies to use 1.3.2 of fabric-shim and error should go away. 1.3.2 locks x509 version to 0.3.3. Writing this post to remind myself that the same code I wrote today may not work tomorrow. When that happens its usually a dependency problem – someone pulled the carpet from below my feet. So its better to always lock the versions of dependencies.

https://github.com/hyperledger/fabric-chaincode-node/commit/d74d08f7a1ff32ac9cf72c82c5bb61f01df93c74#diff-c8e210d41256bc31aa666a384b035418

Btw The actual error that is happening here is

SyntaxError: Unexpected token  in JSON at position 0     at JSON.parse ()     at new ClientIdentity (/usr/local/src/node_modules/fabric-shim/lib/chaincode.js:246:27)     at Chaincode.Invoke (/usr/local/src/chaincode.js:29:17)

The E1219 23:48:19.159391389 19 ssl_transport_security.cc:238] Could not get common name of subject from certificate happens with any chaincode. It happens when following command is run:

> node chaincode.js “–peer.address” “peer1-jnj:7052”

Posted in Software | Leave a comment

Suggested 5 day itinerary for Hawaii

Which Island to Visit? Maui

Where to book? Book flights + hotel + car at costcotravel.com

Total days needed? 7 (1 day to fly in and 1 day to fly back)

Where to stay? for 3 star recommend Napili Surf Beach Resort. For 4-5 star recommend Hyatt Regency or another 4 star property along Kaanapali Beach (Westin, Marriot, Sheraton etc.)

Where not to stay? Napili Shores by Outrigger. Not a disaster but Napili Surf Beach Resort is right next to it and more updated with same price.

What car to rent? Full size car like Hyundai Sonata. We had 4 pieces of baggage (3 carry-on sized, 1 bigger), 2 bagpacks, 1 stroller, 1 carseat for baby and it fit in the Sonata. There is Costco Gas near airport to fill up the tank before returning the car.

Where to rent beach gear? Boss Frog. They have locations all over Maui including Napili, Lahaina, Kihei. You can drop off your gear at any of their locations, not necessarily the one from where you picked it up.

Where to buy groceries? You can buy some on the day you land at the Costco near the airport. On other days there is a good grocery store called Napili Market in the nearby Napili Plaza if you are staying at the Napili Surf Beach Resort. There is also a Safeway in Lahaina.

Day 1 – Lahaina, Front St. Beware of many shops selling discount tickets to helicopter tours and other activities. They will require you to attend some seminar where they will try to sell you some condo or property in Hawaii. Just stay clear of them. Be prepared to pay $7/hr parking.

Day 2 – Maui Ocean Center and adjacent Harbor Shops at Maalaea Harbor. Eat at Seascape and coffee at Hula Cookies in Harbor Shops. You can buy ocean center tickets online at viator.com to get some discount.

Day 3 – Snorkel at Molokini Island. Book at Blue Water Rafting. Rent a wet suit from Boss Frog before going to snorkel. Blue Water Rafting will not provide any wet suit. Eat at Choice Health Bar in Lahaina. Have coffee on the way back at the Coffee Store in Napili Plaza.

Day 4 – Helicopter tour of Hana Rainforest. Book at Maverick Helicopters. I think Maverick is the only operator who does a landing at the Hana Rainforest so you can explore it on foot. Eat at AA Roots in Napili Plaza.

Day 5 – Boogie boarding at the beach. Check out Whaler’s Village and while there buy some cookies at Honolulu Cookies (ask them to validate parking) and spend evening watching Drums of the Pacific Maui at Hyatt Regency. Take some warm jacket as it will get about 10-12 degrees cooler in the night and you might want to have it. Hyatt Regency has valet parking for $5 which is worth it IMO.

Total Distance Covered by car: 300 miles

Further Notes:

  • Be prepared for strong winds.
  • You may rent a beach package from Maui Vacation Equipment including a Coleman tent, baby toys, a cooler and 2 Tommy Bahama Chairs for one week. You pay them in advance and they deliver the gear to your room before you check in at the hotel. They also pick it up and the delivery is included in the price. We did so but didn’t end up using it so YMMV (your mileage may vary).
Posted in Travel | Leave a comment

Unwanted redirect from Gmail to OneLogin

Is Google Chrome redirecting you to onelogin whenever you try to login into any Google account? This is how to fix it:

  1. Open Chrome
  2. Type chrome://settings/siteData
  3. search for onelogin in top right (see example screenshot below)
  4. Capture00
  5. Delete the onelogin cookies
  6. Now try logging to gmail again. Again see the annoying redirect?
  7. This time search for accounts.google.com  in the top right
  8. Delete it (this is the crucial step)
  9. Now it should work.

If the same thing happens with Microsoft, you need to clear cookies for login.microsoftonline.com

Posted in Software | Leave a comment

Installing Bash4

A new macbook pro comes installed with bash version 3. I needed to install bash 4 to be able to use the bash debug vs code extension. To do this run

brew install bash

once its done you will need to edit /etc/shells file so that it looks like following:

WITSC02X6385JGH:temp sjain68$ cat /etc/shells

# List of acceptable shells for chpass(1).

# Ftpd will not allow users to connect who are not using

# one of these shells.

# 4.x of bash

/usr/local/bin/bash

# 3.x of bash

/bin/bash

/bin/csh

/bin/ksh

/bin/sh

/bin/tcsh

/bin/zsh
Posted in Computers, programming, Software | Tagged | Leave a comment