📜 ⬆️ ⬇️

Tcl / Tk. GUI development for command line utilities

Testing a cloud token on various platforms, I did not abandon the thought of some injustice: why the PKCS # 11 token configuration utilities on MS Windows have a graphical interface, but for other platforms it does not. And first of all, it concerns the base utility p11conf , which is available for free use and is a command line utility, which is interacted with via standard I / O.

tkBuilder - graphic designer


The solution would be to write in C / C ++ GUI for the p11conf utility, for example, using the Qt library. But here it came to mind that there is a scripting language of high level Tcl (Tool Command Language), which is in conjunction with the graphic library Tk (Tool Kit) and allows you to quickly create graphical interfaces for console programs or command line utilities. I first met the Tk / Tcl package back in 1997, when it was planned to write a graphical interface for the access control system (ACS). Then the graphics capabilities of the package made a strong impression and, in particular, tetris:

image

One of the reasons for which they refused to use Tk / Tcl was the absence for him at that time of a designer (designer) similar to the current one, say, QT-designer. Refreshing the Tk / Tcl capabilities, and we were interested, in addition to the graphic capabilities, to organize interaction with the command line utilities, and making sure that we were on the right track, we set about searching for the designer. After analyzing the available designers, the choice fell on the designer tkBuilder_for_tcl8.4 :
')
image

Further development has shown the correctness of the choice. The designer was not only with a clear interface, but has excellent functionality. It allows during the development to track the project not only entirely:

image

but also to control its individual parts:

image

The developer can always see the code of the entire project or its part:

image

Interaction with the command line utility, for which the graphical shell is being developed, is conducted via a program channel:

image

When the project is completed, it is necessary to save it in the final tcl file:

image

About fly in the ointment


It would seem that everything, take it and run the utility. But without a spoon (in fact, two spoons) tar is impossible. The first spoon is related to the formation of the xScrollCommand and yScrollComand commands in the widgets (in our case, the text widget), namely:

text .fr1.fr2_list -background #ffffff \ -yscrollcommand [list .fr1.ysc set] -xscrollcommand [list .fr1.scx set] 

They do not want to get into the final file. As a result, they had to register with pens. Well, the second fly in the ointment is classic. The designer tkBuilder_for_tcl8.4 refuses to work with Russian letters (maybe I didn’t understand anything). I emphasize that this applies only to the designer and does not apply to Tcl / Tk, for which Russian is like a native language. Here, too, had to work handles:

 #!/bin/sh # the next line restarts using wish \ exec wish8.5 "$0" ${1+"$@"} wm title . "GUI P11CONF" global p11conf global libpkcs11 set res "" set libpkcs11 "" set p11conf "/usr/local/bin64/p11conf" . configure -background #18f1d7 frame .fr1 -background #18f1d7 grid .fr1 -column 0 -row 0 button .fr1.b1 -command {InitTok . .fr1.fr2_list;} -padx 1 -text "" -width 24 grid .fr1.b1 -column 0 -row 0 button .fr1.b2 -command {ChangeUserPin . .fr1.fr2_list; } -padx 1 -text " USER PIN" -width 24 grid .fr1.b2 -column 0 -row 1 button .fr1.b6_3 -command {ChangeSOPin . .fr1.fr2_list "SO"; } -padx 1 -text " SO PIN" -width 24 grid .fr1.b6_3 -column 0 -row 2 button .fr1.b7 -command {InfoObj . .fr1.fr2_list "Obj"; } -padx 1 -text " " -width 24 grid .fr1.b7 -column 0 -row 3 button .fr1.b8 -command {InfoObj . .fr1.fr2_list "Clear";} -padx 1 -text "  " -width 24 grid .fr1.b8 -column 0 -row 4 button .fr1.b9_6 -command {InfoToken . .fr1.fr2_list; } -padx 1 -text "  " -width 24 grid .fr1.b9_6 -column 0 -row 5 button .fr1.b0 -command {InfoMech . .fr1.fr2_list;} -padx 1 -text " " -width 24 grid .fr1.b0 -column 0 -row 6 button .fr1.b3_8 -command {ChangeSOPin . .fr1.fr2_list "Deblock"; } -padx 1 -text " USER PIN" -width 24 grid .fr1.b3_8 -column 0 -row 7 button .fr1.b4_9 -command {InfoDump . .fr1.fr2_list; } -padx 1 -text "DUMP  " -width 24 grid .fr1.b4_9 -column 0 -row 8 button .fr1.b5_10 -command {exit} -text "" -width 10 

As a result, we received GUI support for the p11conf command line utility through the GUITKP11Conf.tcl utility:

 bash-4.3$ ./GUITKP11Conf.tcl 

image
Now you can safely work with PKCS # 11 tokens, including the LIBLS11CLOUD cloud token, for example, to see which objects are stored on it:

image
The GUIP11CONF.tkb project file and the GUIP11CONF.tcl utility can be downloaded here . The p11conf utility for various platforms can be downloaded here . A little note. In the GUIP11CONF.tcl utility, the path is specified in the p11conf utility (see above):

 global p11conf … set p11conf "/usr/local/bin64/p11conf" 

Most likely, you will have to correct the path to the p11conf utility with your configuration.

Down and Out trouble started


In conclusion, I note that the appetite comes with eating and you already have the desire to write similar graphical shells for command line utilities such as openssl / lirssl (LINK) or NSS (Network Security Services) utilities. As they say, the first step is the hardest.

PS Continued here .

Source: https://habr.com/ru/post/332924/


All Articles