Parsing X server authorization file - xorg

Is there any API's or documentation to facilitate in parsing the authorization file for X server?
I am using xcb to connect to a display. It accepts a xcb_auth_info_t struct for authorization info. However, I cannot find any information on how to build this structure. There doesn't seem to be any documentation on the format of the X server authorization files.
Solution I settled with:
It turns out, for MIT-MAGIC-COOKIE-1 type X authority files, the Xauth structure (from X11/Xauth.h) members map directly to the xcb_auth_info_t members. So, just read an Xauth structure from your X authority file using XauReadAuth. Then copy over the name, name_length, data, and data_length members.
If you want a more portable way to parse the X authority file, you can refer to xcb's source code. It is pretty messy, but it shouldn't be too difficult to adapt their source code for your own purposes. Refer to xcb_util.c for details on how to open a socket to a display. Once you have the socket, you can use methods from xcb_auth.c to create the xcb_auth_info_t struct (see the methods _xcb_get_auth_info, get_auth_ptr, and compute_auth).
I only needed to connect through unix sockets (AF_UNIX), so the code I ported over was fairly minimal. I mostly just used the compute_auth method (and its dependencies).

The authorization protocols and files are discussed briefly in the xauth and Xsecurity manual pages, and in more detail in those for the Xau library functions (XauWriteAuth etc.). The xcb_auth_info_t structure appears to be defined in the /usr/include/xcb/xcb.h file as follows:
/**
* #brief Container for authorization information.
*
* A container for authorization information to be sent to the X server.
*/
typedef struct xcb_auth_info_t {
int namelen; /**< Length of the string name (as returned by strlen). */
char *name; /**< String containing the authentication protocol name, such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1". */
int datalen; /**< Length of the data member. */
char *data; /**< Data interpreted in a protocol-specific manner. */
} xcb_auth_info_t;

After some searches, it is like you doesn't have to build this structure yourself. Looks at this discussion:
What's the right way to call xcb_connect_to_display_with_auth_info() given a Xauthority file
The Xauthory file is specified in the XAUTHORITY environement variable. This file is generated by the program that start the X server (xdm, startx or xauth itself for example according to the doc in man xauth)
A classical connection with auth file specified via the XAUTHORITY variable works like this :
xcb_connect call xcb_connect_with_auth_info() with a auth info set as NULL
xcb_connect_with_auth_info() call _xcb_get_auth_info() in order to get auth information from the default xauthority file.
If you really want to see how this function get the auth info:
git clone git://anongit.freedesktop.org/xcb/libxcb
Look at the file ./libxcb/src/xcb_util.c lines 478 to end
Look at the file ./libxcb/src/xcb_auth.c lines 312 to 379 for _xcb_get_auth_info()

Related

Mock real gRPC server responses

We have a microservice that needs to be integration tested (real calls, but no network communication with anything outside of the test namespace in kubernetes) in our pipeline. It also relies on an external gRPC server which we have no control over.
Above is a picture of what we'd like to have happen. The white box on the left is code that provides the Microservice Boundary with 'external' data. It then keeps calling the Code via REST until it gets back the proper number of records or it times out. The Code pulls records from an internal database, as well as data associated to those records from a gRPC call. Since we do not own the gRPC service, but are doing integration tests, we need a few pre-defined responses to the two gRPC services we call (blue box).
Since our integration tests are self-contained right now, and we don't want to write an entirely new actual gRPC server implementation just to mimick calls, is there a way to stand up a real gRPC server and configure it to return responses? The request is pretty much like a mock setup, except with an actual server.
We need to be able to:
give the server multiple proto files to interpret and have it expose those as endpoints. Proto files must be able to have different package names
using files we can store in source control, configure the responses to each call
able to run in a linux docker container (no windows)
I did find gripmock which seemed almost exactly what we need, but it only serves one proto file per container. It supposedly can serve more than one, but I can't get it to work and their example that serves two files implies each proto file must have the same package name which will likely never happen with our scenarios. In the meantime we are using it, but if we have 10 gRPC call dependencies, we now have to run 10 gripmock servers.
Wikipedia contains a list of API mocking tools. Looking at that list today there is a commercial tool that supports gRPC called Traffic Parrot which allows you to create gRPC mocks based on your Proto files. You can give it multiple proto files, store the mocks in Git and run the tool in Docker.
There are also open-source tools like GripMock but it does not generate stubs based on Proto files, you have to create them manually. Also, the project up to today was not keeping up to date with Proto and gRPC developments i.e. the package name issue you have discovered yourself above (works only if the package names in different proto files are the same). There are a few other open-source tools like grpc-wiremock, grpc-mock or bloomrpc-mock but they still lack widespread adoption and hence might be risky to adopt for an important enterprise project.
Keep in mind, the mock generated will be only a test double, it will not replicate the full behaviour of the system the Proto file corresponds to. If you wanted to also replicate partially the semantics of the messages consider doing a recording of the gRPC messages to create the mocks, that way you can see the sample data as well.
Take a look at this JS library which hopefully does what you need:
https://github.com/alenon/grpc-mock-server
Usage example:
private static readonly PROTO_PATH: string = __dirname + "example.proto";
private static readonly PKG_NAME: string = "com.alenon.example";
private static readonly SERVICE_NAME: string = "ExampleService";
...
const implementations = {
ex1: (call: any, callback: any) => {
const response: any =
new this.proto.ExampleResponse.constructor({msg: "the response message"});
callback(null, response);
},
};
this.server.addService(PROTO_PATH, PKG_NAME, SERVICE_NAME, implementations);
this.server.start();

How does telegraf input plugin like [[inputs.mem]] fetch data?

When we need memory related stats we add input plugin in telegraf.conf file.
[[inputs.mem]]
For application stats we keep input as statsd, we push stats from application using UDP to telegraf using its host and port.
[[inputs.statsd]]
Could someone explain how does [[inputs.mem]] input plugins get data related to memory? Because no one is pushing data to telegraf in this case.
Telegraf retrieves system data using system libraries written for Go. At this time it is using the gopsutil library. This library's link above includes an example of how it could be used within any Go program.
func main() {
v, _ := mem.VirtualMemory()
// almost every return value is a struct
fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
// convert to JSON. String() is also implemented
fmt.Println(v)
}
This library supports a number of different operating systems and has modules for a variety of system information such as cpu, memory, disk, and networking usage. You can see where these are incorporated into the telegraf project here.

Stonestreet One's Bluetopia how do you request a MTU change?

Or more specifically how do you request an MTU change when operating at the "Platform Manager" level?
More details
I'm using the sample program LinuxGATM_CLT which acts as a GATT client and it uses the Bluetopia Platform Manager Framework.
I'm using TI's WL183xMOD WiLink hardware which uses Bluetopia (previously owned by Stonestreet One).
The API call exists
The function exists, but seems to be at stack layer lower than the PM:
~/src/ti_bluetopia/ $ grep GATT_Exchange_MTU_Request ./BluetopiaPM/Bluetopia/include/GATTAPI.h
BTPSAPI_DECLARATION int BTPSAPI GATT_Exchange_MTU_Request(unsigned int BluetoothStackID, unsigned int ConnectionID, Word_t RequestedMTU, GATT_Client_Event_Callback_t ClientEventCallback, unsigned long CallbackParameter);
But its not callable from the "Platform Manager" level
Everything within BluetopiaPM/sample/LinuxGATM/LinuxGATM_CLT.c uses GATM functions from BluetopiaPM/include/client/GATMAPI.h
It feels like the GATT_Exchange_MTU_Request() function has not been exposed at the PM level. Its hard to dig deeper into how the PM works because they only ship binaries (doesn't seem to be open-source). For example the only match is the GATTAPI.h header file and a binary library file:
~/src/ti_bluetopia/ $ grep -ri GATT_Initialize ./
Binary file ./BluetopiaPM/Bluetopia/lib/libSS1BTGAT.a matches
I feel like the solution is to find methods to report my current Platform Manager BluetoothStackID, ConnectionID, and callback parameters so that I can call the GATT_Exchange_MTU_Request() function directly.
In short, the workaround is to get an earlier version of Stonestreet One's Bluetopia, before they created the "Platform Manager". These earlier versions (suchas 4.012 and 4.013) don't have the advantage of the Platform Manager, but they do allow you to have more control, operating at a lower level where you can call:
GATT_Initialize() and
GATT_Exchange_MTU_Request()
One good example is 4.013's SPPLEDemo.c which calls the above-mentioned methods.

Bluetooth LE : Address Type

I am working on the iBeacon technology and I can't find any answer to a particular point concerning the address type.
I found the documenation (bluetooth specification) explaining what are the address types but I can't seem to find how to chose between the two types (public and random).
Here is an example where I found it (it is a sniffed packet transmitted by an iBeacon on a Raspberry PI) :
http://i.stack.imgur.com/QF5gf.png
and http://i.stack.imgur.com/NHY6x.png (sorry I can't post images yet because of my reputation)
Let's try to ask questions and make it more specific :
Since a public address has to be valid, might it be that there is a command to generate a random one (yet correct in formatting the address) to assign it to the concerned device?
If the above is true : what would be the command? and how do you roll back (to the primary public address)?
Or is there a "switch" that allows to chose between the (valid) public address or to generate a random one?
Thank you.
Here's a command that looks pretty much like what you want. See here for details.
Set Static Address Command
==========================
Command Code: 0x002B
Controller Index: <controller id>
Command Parameters: Address (6 Octets)
Return Parameters:
This command allows for setting the static random address. It is
only supported on controllers with LE support. The static random
address is suppose to be valid for the lifetime of the
controller or at least until the next power cycle. To ensure
such behavior, setting of the address is limited to when the
controller is powered off.
The special BDADDR_ANY address (00:00:00:00:00:00) can be used
to disable the static address.
When a controller has a public address (which is required for
all dual-mode controllers), this address is not used. Only when
the controller information reports BDADDR_ANY (00:00:00:00:00:00),
it is required to configure a static address first.
If privacy mode is enabled and the controller is single mode
LE only without a public address, the static random address is
used as identity address.
This command generates a Command Complete event on success or a
Command Status event on failure.
Possible errors: Rejected
Not Supported
Invalid Parameters
Invalid Index
It looks to me like the privacy features of BlueZ are under current active development and may not be complete yet. See this commit from 2014/02/18. If you want to try this with the latest updates, you will have to compile BlueZ from source.

Encrypting a Private Message

I am using both the Private Message module and the Encrypt modules. I can of course create a field which is encrypted, but it looks like I must alter the PM module since its storage in the database is not encrypted. Isn't exactly private then is it. Permissions are not enough to make it a Private Message.
I assume I will need to add the Encrypt code directly to the module itself. Does anyone have any idea where I would add it and how?
Thanks
The module is named "private messages" because the messages are private between the sender & recipient, no one else can see the messages.
If you want to encrypt the database, then you can directly use the database API hooks. You will also have to alter the schema of private messages module I believe.
For HTTPS you can use https://drupal.org/project/securepages
And for encrypting the form submitted data, you can go with http://www.jcryption.org/ or even more interesting http://crypto.stanford.edu/sjcl/
I've done something similar before to store encrypted images directly in the DB (for passport photos).
I've just had a quick look at the private messages module and it looks like you'll need to modify the main .module file. Search though it for db_insert. At around line 1836 is the bit that saves the message to the db.
If you add:
$message->body = encrypt($message->body);
before the line:
$args['body'] = $message->body;
Then that will handle the encryption.
Then you need to find where it gets back out the DB and put the decryption function in there.

Resources